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

column into a row using select Expand / Collapse
Author
Message
Posted Thursday, November 29, 2007 2:12 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, October 14, 2009 1:56 AM
Points: 438, Visits: 754
Hi,

how to make a column into a row using select statement.
For ex,


ID Col1 Col2
--------------------
1 A B
2 D E


Output Should like this.

ID Col1
------------
1 A
1 B
2 D
2 E


Thanks in Advance
Post #427279
Posted Thursday, November 29, 2007 2:17 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, February 4, 2013 7:02 AM
Points: 465, Visits: 94
try the below querry
select id, col1 from table
union all
select id, col2 as 'col1' from table
order by col1
Post #427284
Posted Thursday, November 29, 2007 2:44 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, October 14, 2009 1:56 AM
Points: 438, Visits: 754
Thanks working fine
Post #427297
Posted Thursday, November 29, 2007 4:48 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 2,717, Visits: 3,844
And for more complex "Columns into Rows/Rows into Columns" Look up the PIVOT and UNPIVOT functions new to 2005. They've proven quite handy.

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Post #427343
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse