Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Table Nmae:: Oppertunity. Fields Name:: 1] EstimatedValue 2]EstimatedDate I want Sum of Estimatedvalue of last 3 year by Month wise using EstimatedDate. OutPut Should be:: EstimatedValue Year MonthName 3567.00 2015 January 1173.60 2015 February . . . . . . . . 2212.21 2015 December 54545.21 2014 January . 2014 . . 2014 . 2312.21 2014 December 54545.1 2013 January . 2013 . . 2013 . 2312.21 2013 December
magmo
Aged Yak Warrior
558 Posts
Posted - 2015-04-10 : 04:23:57
How about this...
SELECT SUM(EstimatedValue), DATENAME(year, EstimatedDate) AS Year, DATENAME(month, EstimatedDate) AS MonthNameFROM dbo.OppertunityGROUP BY DATENAME(month, EstimatedDate), DATENAME(year, EstimatedDate), MONTH(EstimatedDate)ORDER BY Year, MonthNumber
abhijit1062
Starting Member
4 Posts
Posted - 2015-04-10 : 05:34:21
Yes its close... I just detailed my output again.The condition is that it should show all months in a year with there 0 value in EstimatedValue column.Output::EstimatedValue Year MonthName356 2015 January117 2015 February1212. 2015 March0.00 2015 April0.00 2015 May0.00 2015 June0.00 2015 July0.00 2015 August0.00 2015 September0.00 2015 October0.00 2015 November0.00 2015 Decemberand same again for year 2014 and so on.Thanks Magmo
magmo
Aged Yak Warrior
558 Posts
Posted - 2015-04-10 : 06:03:34
In that case just add WHERE SUM(EstimatedValue) = 0