johnkainn
asked on
ORDER BY items must appear in the select list if SELECT DISTINCT is specified
Hello,
I have following code in sql:
SET @myCol = STUFF(( SELECT DISTINCT
'],[' + ltrim(cast(AId as varchar(10)))
FROM dbo.temp
ORDER BY '],[' + ltrim(cast(AId as varchar(10)))
FOR XML PATH('') ), 1, 2, '') + ']'
I get the error: ORDER BY items must appear in the select list if SELECT DISTINCT is specified
Do you know how to fix this?
I have following code in sql:
SET @myCol = STUFF(( SELECT DISTINCT
'],[' + ltrim(cast(AId as varchar(10)))
FROM dbo.temp
ORDER BY '],[' + ltrim(cast(AId as varchar(10)))
FOR XML PATH('') ), 1, 2, '') + ']'
I get the error: ORDER BY items must appear in the select list if SELECT DISTINCT is specified
Do you know how to fix this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or just use "order by 1"