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



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: Wednesday, March 10, 2010 3:20 AM
Points: 422, Visits: 91
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


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 3:47 PM
Points: 1,287, Visits: 1,699
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.


~Why push the envelope when you can just open it?

Jason Selburg


Post #427343
« Prev Topic | Next Topic »


Permissions Expand / Collapse