Linked Questions

Popular Questions

UDF with CTE column name is not specified Error

Asked by At

This query I can run successfully standalone but as soon as I put in UDF,

> column name is not specified for column

error came up. table is like

Name a b c d e
Peter 1 2 3 2 1
Linda 1 2 2 2 1

for example I have simplified query like

ALTER FUNCTION [dbo].[test] 

RETURNS TABLE 
AS
RETURN 

    WITH CTE AS(SELECT 
    a,b,c,d,e
    FROM nametable)
    SELECT
    a,
    b,
    Count(d),
    avg(c)
    FROM CTE Group By a,b

As soon as I remove Count(d), it works but when I add it in I cannot alter the function. Same query I can run standalone at SSMS.

Related Questions