Ordering of month/year pairs in T-SQL query
Posted
by Surya sasidhar
on Stack Overflow
See other posts from Stack Overflow
or by Surya sasidhar
Published on 2010-04-01T06:05:00Z
Indexed on
2010/04/01
11:23 UTC
Read the original article
Hit count: 632
I am writing a stored procedure for displaying month and year. It is working, but it is not returning the rows in the desired order.
ALTER procedure [dbo].[audioblog_getarchivedates]
as
begin
select DateName(Month,a.createddate) + ' ' + DateName(Year,a.createddate) as ArchiveDate
from audio_blog a
group by DateName(Month,a.createddate) + ' ' + DateName(Year,a.createddate)
order by DateName(Month,a.createddate) + ' ' + DateName(Year,a.createddate) desc
end
Results will come like this:
March 2010
January 2010
February 2010
But that is not in a order (desc).
© Stack Overflow or respective owner