Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Cross-tab, Pivot or what?


Message #1 by "William Markham" <William.Markham@p...> on Thu, 11 Oct 2001 15:21:13
Try this

SELECT Year, 
CASE QUARTER WHEN 1 THEN SOMEINFO ELSE '' END as 'Q1', 
CASE QUARTER WHEN 2 THEN SOMEINFO ELSE '' END as 'Q2', 
CASE QUARTER WHEN 3 THEN SOMEINFO ELSE '' END as 'Q3', 
CASE QUARTER WHEN 4 THEN SOMEINFO ELSE '' END as 'Q4' 
FROM table 
GROUP BY Year

Should give you a start, should give result

	Q1	Q2	Q3	Q4

Y1
Y2
Y3
...

Alastair Ramsay


-----Original Message-----
From: William Markham [mailto:William.Markham@p...]
Sent: 11 October 2001 16:21
To: sql language
Subject: [sql_language] Cross-tab, Pivot or what?


Suppose I have a table.  

YEAR      QUARTER        SOMEINFO         
  1          1              x                   
  1          2              x                   
  1          3              x                   
  1          4              x                   

  .          .              .                   
  .          .              .                   
  .          .              .                   

  4          1              x                   
  4          2              x                   
  4          3              x                   
  4          4              x                   

The table has been created this way over the years and can't be changed 
itself.  But I want the years to be turned into the column headings.
I am new to the sql language, but did manage to get this to work in access.
Now I have to get it done with sql 2000.  I would appreciate any help with 
this.
Thanks
William Markham

  Return to Index