gazy007 (7/2/2015)
Thanks Luis, But I am not getting right numbers for 2015 and 2016 as we need to get for the whole year rather than getdate() or today. I hope I am making sense here.SUM(CASE WHEN YEAR(PeriodEnd) = YEAR(DATEADD(YY, 0,)))) THEN Value Else 0 End) as '2015'
SUM(CASE WHEN YEAR(PeriodEnd) = YEAR(DATEADD(YY, 1,)))) THEN Value Else 0 End) as '2016'
Thanks Luis.
Since you are hard coding the column labels ('2015', '2016'), why don't you simplify the query with:
SUM(CASE WHEN YEAR(PeriodEnd) = 2015 THEN Value Else 0 End) as '2015'
Don Simpson