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)
 SQL date field 2014-01-01 to JAN 2014

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-08-20 : 13:47:54

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

38200 Posts

Posted - 2014-08-20 : 13:54:37
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

97 Posts

Posted - 2014-08-20 : 14:06:04
date
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-20 : 14:23:29
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
   

- Advertisement -