I am concatinating two columns together, ID and Name. But I want it to order by the name which is 9 characters over. I can't seem to find the right syntax. Can anyone tell me what is wrong? I have tried:
SELECT DISTINCT ID + ' ' + NAME as ID_NAME FROM TGroups ORDER BY substring(ID + ' ' + NAME,9,20)
I get the error:
Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.