Transpose column into rows

Transpose column into rows

am 29.05.2007 11:52:43 von Oonz

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

Re: Transpose column into rows

am 29.05.2007 14:37:02 von Plamen Ratchev

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