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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql Query for Poupulating List

Author  Topic 

mahesh.sanka
Starting Member

18 Posts

Posted - 2012-09-03 : 02:27:42

Hi All,

I have one table which contains Datetime filed.

CALLDATE

2012-05-02
2012-04-02
2012-03-02
2012-03-05

Now i have to build a query in such a way that the o/p should be in the following format

March-2012 2
April-2012 1
May-2012 1

Please guide me in this query building

Thanks in Advance



Thanks & Regards,
Mahesh Kumar Sanka

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-03 : 04:30:17
[code]
select datename(month, CALLDATE) + '-' + datename(year, CALLDATE), count(*)
from yourtable
group by datename(year, CALLDATE), datename(month, CALLDATE)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mahesh.sanka
Starting Member

18 Posts

Posted - 2012-09-03 : 04:54:36
Thanks very much for your help. My Problem has been solved.

Thanks & Regards,
Mahesh Kumar Sanka
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-03 : 15:19:24
i would suggest doing this at front end if possible especially if you've plans of doing some date manipulations like sorting,comparison etc with this returned resultset else it makes manipulations difficult due to conversion of data type to varchar just for formatting functions.
I'm more comfortable in bring them as date values itself and then doing the formatting at front end using date functions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -