Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Counts by month and year
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

97 Posts

Posted - 08/20/2014 :  10:47:41  Show Profile  Reply with Quote
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,
MAR 2014 FRIM ABC 80
and so on.

Please advise

Aged Yak Warrior

737 Posts

Posted - 08/20/2014 :  10:58:03  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000