Select * from Table 1
Order by date
It works fine when all the dates are in the same year, but if there are dates in different year, then we see entries like this
11-26-2008
11-26-2009
12-01-2008
For some reason sql server seemed to sort the datetime field by the order of month, day, year. To fix this, we need to change the order by statement to sort the year component first.
Select * from Table 1or
Order by year(date), date
Select * from Table 1
Order by datepart(year, date), date
The result is now correct
11-26-2008
12-01-2008
11-26-2009
No comments:
Post a Comment