dbTalk Databases Forums  

Transpose column into rows

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Transpose column into rows in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Oonz
 
Posts: n/a

Default Transpose column into rows - 05-29-2007 , 04:52 AM






Hi Friends,


How to transpose the columns into rows

i want to convert the table which looks like this
ID Name HomePhone WorkPhone Email
1 test1 678364 643733 test1 (AT) test (DOT) com
2 test2 678344 643553 test2 (AT) test (DOT) com


to a table which should look like this
ID Name Device
1 test1 678364
1 test1 643733
1 test1 test1 (AT) test (DOT) com
2 test2 678344
2 test2 643553
2 test2 test2 (AT) test (DOT) com


Thanks in Advance
Arunkumar


Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Transpose column into rows - 05-29-2007 , 07:37 AM






Using UNPIVOT in SQL Server 2005:

SELECT ID, Name, Device
FROM Foobar
UNPIVOT
(Device FOR DeviceType IN
(HomePhone, WorkPhone, Email)) AS U;

HTH,

Plamen Ratchev
http://www.SQLStudio.com




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.