I am trying to write a SP Select Statement to select distinct rows that contains concatenated fields and to sort depending on a parameter value
This is the error that I get
Any workaround??
Code:
Select Distinct A +','+ B As Field1 ,C + ',' + B As Field2,.....
From TableName
inner join ......
Order by
Case @OrderBy when 1 then A +','+ B end,
Case @OrderBy when 1 then C +','+ D end
This is the error that I get
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Any workaround??