|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 3:26 AM
Points: 156,
Visits: 567
|
|
Hi geniuses!
I have this query
SELECT DISTINCT chapter, Sum(dbo.FGG.Value) AS FGG2010 FROM FGG WHERE (FGG.YEAR= 2010) and (dbo.FGG.valueType = '02 - FGG01l') Group by chapter
It retrieves :
chapter | FGG2010 A | 1$ B | 2$ C | 3$
What I want is to add in 'Sum(dbo.FGG.Value) AS FGG2011' where FGG.YEAR=2011 in the same query, in order to retrive:
chapter | FGG2010 | FGG2011 A | 1$ | 2$ B | 2$ | 33$ C | 3$ | 11$
Thanks in advance! Regards
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 2:18 PM
Points: 4,434,
Visits: 7,219
|
|
Use a CASE expression in your SUM statement, something like this:
... SUM(CASE WHEN Year = 2010 THEN Amount ELSE 0 END) AS Total2010, SUM(CASE WHEN Year = 2011 THEN Amount ELSE 0 END) AS Total2011 ...
Alternatively, you could use PIVOT. Or you could write a report in Reporting Services to display your data in the way you need.
John
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 3:26 AM
Points: 156,
Visits: 567
|
|
|
|
|