keshava.murthy (5/28/2013)
If I try order by month( startdatetime) then it sorts the data by month.The problem here is when the data spans to multiple years then it will sort as follows:
Jan 2011 450 4000
Jan 2012 200 3651
Feb 2011 300 6354
Feb 2012 400 2654
I want result set instead as follows:
Jan 2011 450 4000
Feb 2011 300 6354
till Dec 2011 and then
Jan 2012 200 3651
Feb 2012 400 2654
and so on
Your query had a where clause that would prevent data from any year other than 2011.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/