Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
satheesh
Posting Yak Master
152 Posts |
Posted - 2014-07-02 : 06:50:43
|
Hi,I have to calculate total policies sold per month. I wrote the below query and i am getting the output like below but i need to display the month in the format year and month (2013 January)select dateadd(month, datediff(month, 0, Policy .DateCreated ), 0) as Month, COUNT(policy.PolicyNumber) as Countfrom Policy where(policy.datecreated between '2013-01-01 00:00:00.000' AND '2013-06-30 23:59:59.997') GROUP BY dateadd(month, datediff(month, 0, Policy .DateCreated), 0)order by dateadd(month, datediff(month, 0, Policy .DateCreated), 0)OutputMonth Count2013-01-01 00:00:00.000 41532013-02-01 00:00:00.000 39042013-03-01 00:00:00.000 7854----But i need to display as Month Count2013 January 41532013 February 3904----i.e Month column in year and month format. How to modify the above query. Any help will be highly appreciated.ThanksRegards,SG |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-07-02 : 07:41:37
|
try this:select cast(year(getdate()) as char(4)) + ' ' + datename(month, getdate()) |
|
|
|
|
|
|
|