I need to display distinct values of a datetime field called datetimestamp from a SQLServer 2005 table in the MMM YYYY format. I also need them to be sorted in chronological order.
So far I have this:
Select distinct CONVERT(CHAR(4), datetimestamp, 100) + CONVERT(CHAR(4), datetimestamp, 120) as MonthYear from TableName order by MonthYear
The "order by" of course sorts it in alpha order due to the conversion.
Apr 2009
Dec 2009
Feb 2009
How do I get it to sort it in chronological order?
Feb 2009
Apr 2009
Dec 2009
Thanks.