SQL Server Forums
Profile | Register | 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
 New Topic  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

733 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000