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)
 SQL date field 2014-01-01 to JAN 2014
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Blessed1978
Yak Posting Veteran

65 Posts

Posted - 08/20/2014 :  13:47:54  Show Profile  Reply with Quote

DATE TOTAL
how to convert 2014-01-01 3
2014 -01- 02 4
2014-01-02 5

2014-02-01 5
2014 -02- 02 8
2014-02-02 7

to
(BASICALLY DO A COUNT FOR EACH MONTH)

JAN 2104 12 --- Jan total
FEB 2014 20 --- FEB total

tkizer
Almighty SQL Goddess

USA
37143 Posts

Posted - 08/20/2014 :  13:54:37  Show Profile  Visit tkizer's Homepage  Reply with Quote
What data type is the date column?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Blessed1978
Yak Posting Veteran

65 Posts

Posted - 08/20/2014 :  14:06:04  Show Profile  Reply with Quote
date
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37143 Posts

Posted - 08/20/2014 :  14:23:29  Show Profile  Visit tkizer's Homepage  Reply with Quote
select DATEADD(MONTH, DATEDIFF(MONTH, 0,datecol), 0), sum(total)
from @t
group by DATEADD(MONTH, DATEDIFF(MONTH, 0,datecol), 0)

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
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