MSSQL 2005 - ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

Today another error is appearing where the ORDER BY has a field in it where the SELECT DISTINCT list doesn't.  And SQL server is throwing an error.  How nice.

Here is a code example that will cause an error:

select distinct
     datepart(dd,visitDate), fld2
from tbl
order by visitDate



Fix  :

select distinct

     datepart(dd,visitDate), fld2

from tbl

order by datepart(dd,visitDate)




Comments

Popular posts from this blog

ColdFusion in an Enterprise Environment - Part 1 - Understanding how to use SubVersion (SVN)

coldfusion builder 2 extension not displaying browse button on type=projectdir

Being Thread Safe in Coldbox/Coldfusion