Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am wring an query in sql,my query like

SQL
select [Month],[Year] from [dbo].[ScoreCard_Accounts] where (Year='2015' or Year='2014') and Service is null order by Year(Year) asc,DATEPART(mm,CAST([Month]+ ' 1900' AS DATETIME)) asc


But i am getting below result
Jan	2015
Jan	2014
Feb	2014
Feb	2015
Mar	2015
Mar	2014
Apr	2014
Apr	2015


But i need like

Jan 2014
Jan 2015
Feb 2014
Feb 2015
Mar 2014
Mar 2015
Apr 2014
Apr 2015........


Please any one help how to write query in sql

Thanks
Pradeep
Posted

1 solution

use an ORDER BY clause after any WHERE clause
You will have to calculate a MONTH int column so you can order by that first and the year second.

You can be clever or have an
SQL
ORDER BY
  (CASE monthColumn
      WHEN 'Jan' then 1
      ...
      WHEN 'Dec' then 12
   end ),
   yearColumn
 
Share this answer
 
v3
Comments
Pradeep Rao M 12-Jun-15 6:59am    
Thank You, its working perfect.
Andy Lanng 12-Jun-15 7:01am    
awesome. Well done

Don't forget to accept the solution ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900