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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Counts by month and year

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-08-20 : 10:47:41
I have a table with a date field in the format yyyy-mm-dd (2014-08-20) and a firm field. i HAVE data going all the way back to 2004. i would like to do a count on all firms broken dowm by month and year
so the end results should be JAN 2014 FIRMABC 56,
FEB 2014 FIRMABC 78
MAR 2014 FRIM ABC 80
and so on.

Please advise

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-08-20 : 10:58:03
select month(datecolumn) as [Month],
year(datecolumn) as [Year],
count(firm field) as [count]
from your table
group by month(datecolumn),year(datecolumn)
order by year,month

Javeed Ahmed
Go to Top of Page
   

- Advertisement -