SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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  

Blessed1978
Yak Posting Veteran

65 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,
FEB 2014 FIRMABC 78
MAR 2014 FRIM ABC 80
and so on.

Please advise

ahmeds08
Aged Yak Warrior

India
656 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.11 seconds. Powered By: Snitz Forums 2000