Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Transpose column data to row

Author  Topic 

Lewis
Starting Member

6 Posts

Posted - 2010-05-11 : 15:09:54
Hi, I want to transpose a column into row. How can I do this?

Thanks,
Lewis

column1
column2 => column1 column2 column3 column4
column3
column4

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-11 : 15:13:09
If I understood you correctly, you can use UNPIVOT operator to do this. Check out UNPIVOT in BOL for more information. While you're at it, also check out PIVOT.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Lewis
Starting Member

6 Posts

Posted - 2010-05-11 : 15:22:26
Isn't unpivot doing the opposite transformation? I didn't get it. I only want to transform values in one column to a row. Thanks.

quote:
Originally posted by tkizer

If I understood you correctly, you can use UNPIVOT operator to do this. Check out UNPIVOT in BOL for more information. While you're at it, also check out PIVOT.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-11 : 15:25:42
If it's the opposite, then use PIVOT instead. If this still isn't what you want, then please post a data example to make your issue more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-12 : 06:00:51
Refer this
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -