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.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-11-21 : 04:34:15
|
Hi All Sorry to bother you, I need some further help Aim – make the following date in column “Months” displayed as the months, eg January,February, March etcThe close date in the table ‘# Build is displayed as ” Year, Month, day” some examples are “2010-03-26”,“2012-03-15”“2012-05-02”“2012-05-08”Query select DATEADD(mm,DATEDIFF(mm,0,CloseDate),0)as Months,sum([Total_Contract_Value__c]) as SalesFROM #buildwhere [Channel Indicator] = 'Field'and [StageName] in ('Live Transactions', 'Approved by Risk')and year(CloseDate) = '2013'group by DATEADD(mm,DATEDIFF(mm,0,CloseDate),0)which provides the following results Months Sales2013-01-01 00:00:00.000 944547.662013-02-01 00:00:00.000 784935.912013-03-01 00:00:00.000 700572.662013-04-01 00:00:00.000 601489.672013-05-01 00:00:00.000 1021441.002013-06-01 00:00:00.000 698085.492013-07-01 00:00:00.000 543487.992013-08-01 00:00:00.000 765430.002013-09-01 00:00:00.000 625714.002013-10-01 00:00:00.000 691163.002013-11-01 00:00:00.000 334358.002013-12-01 00:00:00.000 104794.00Really looking for your help |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-11-21 : 04:42:18
|
datename( month, <date column> ) KH[spoiler]Time is always against us[/spoiler] |
 |
|
SergioM
Posting Yak Master
170 Posts |
Posted - 2013-11-21 : 11:04:00
|
Yep, what he said.SELECT DATENAME(MONTH, DATEADD(mm,DATEDIFF(mm,0,CloseDate),0)) ,SUM([Total_Contract_Value__c]) as SalesFROM #buildWHERE [Channel Indicator] = 'Field' AND [StageName] in ('Live Transactions', 'Approved by Risk') AND YEAR(CloseDate) = '2013'GROUP BY DATEADD(mm,DATEDIFF(mm,0,CloseDate),0) -SergioI use Microsoft SQL 2008 |
 |
|
|
|
|
|
|