Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / May 2007

Tip: Looking for answers? Try searching our database.

Transpose column into rows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oonz - 29 May 2007 10:52 GMT
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 - 29 May 2007 13:37 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.