Connecting Tech Pros Worldwide Forums | Help | Site Map

Transpose column into rows

Oonz
Guest
 
Posts: n/a
#1: May 29 '07
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@test.com
2 test2 678344 643553 test2@test.com


to a table which should look like this
ID Name Device
1 test1 678364
1 test1 643733
1 test1 test1@test.com
2 test2 678344
2 test2 643553
2 test2 test2@test.com


Thanks in Advance
Arunkumar


Plamen Ratchev
Guest
 
Posts: n/a
#2: May 29 '07

re: Transpose column into rows


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



Closed Thread