Cross-Tab Question

  • 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

  • This was removed by the editor as SPAM

  • Not without dynamic SQL.



    --Jonathan

  • 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