Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to write this SQL ? Expand / Collapse
Author
Message
Posted Saturday, August 11, 2012 6:54 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, August 12, 2012 7:36 PM
Points: 4, Visits: 8
I can't figure this out, Please help...
SQL Problem --
We have a table of orders.
CREATE TABLE Orders (ordernumber INT, rownumber INT, Description VARCHAR(10))
The rownumber is guaranteed to always between 1 and 5 and is always filled in consecutively.
Write SQL that will return the rownumbers as column headers, with the description as the column values. Output similar to below:

Order# Row1 Row2 Row3 Row4 Row5
10 Desc1 Desc2
20 Desc1 Desc2 desc3

Please help... Thanks!
Post #1343839
Posted Saturday, August 11, 2012 10:05 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, December 11, 2014 9:24 AM
Points: 994, Visits: 2,232
This is called PIVOT or CROSS TAB query.
Post #1343850
Posted Sunday, August 12, 2012 7:38 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, August 12, 2012 7:36 PM
Points: 4, Visits: 8
OK, I see, use pivot tab, thanks for the link and your help.
Post #1343951
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse