Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Order By with Concatination

$
0
0

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.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>