February 20, 2004 at 7:57 am
Hello,
Lets say I have the following query (this is the example from BOL):
SELECT Year,
SUM(CASE Quarter WHEN 1 THEN Amount ELSE 0 END) AS Q1,
SUM(CASE Quarter WHEN 2 THEN Amount ELSE 0 END) AS Q2,
SUM(CASE Quarter WHEN 3 THEN Amount ELSE 0 END) AS Q3,
SUM(CASE Quarter WHEN 4 THEN Amount ELSE 0 END) AS Q4
FROM Northwind.dbo.Pivot
GROUP BY Year
Is there a way that I could express the column name so that it
matches the value of 'Quarter' for each CASE statement?
SELECT Year,
SUM(CASE Quarter WHEN 1 THEN Amount ELSE 0 END) AS (Value of Quarter),
SUM(CASE Quarter WHEN 2 THEN Amount ELSE 0 END) AS (Value of Quarter),
SUM(CASE Quarter WHEN 3 THEN Amount ELSE 0 END) AS (Value of Quarter),
SUM(CASE Quarter WHEN 4 THEN Amount ELSE 0 END) AS (Value of Quarter)
FROM Northwind.dbo.Pivot
GROUP BY Year
Thank you for your help!
CSDunn
February 23, 2004 at 8:00 am
This was removed by the editor as SPAM
February 23, 2004 at 11:54 am
Not without dynamic SQL.
--Jonathan
February 23, 2004 at 2:23 pm
I was looking for and idea make a report in a client application work, but I have come up with another idea that will incorporate two cross-tab SQL Server reports that should work fine.
Thanks!
CSDunn
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply