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)
 how do i convert rows to columns?

Author  Topic 

petre
Starting Member

11 Posts

Posted - 2010-10-03 : 00:20:08
hi friends,

i have a table @tmp that has two columns but four rows

it slooks liek this:

id csv_values
1 hello <---- maps to message column in table1
2 f <---- maps to is_valid column in table1
3 1 <---- maps to is_active column in table1

each row should be represent a column in abnother table
suchas
table1
message | is_valid | is_actve


therefore i need to convert those rows in the @tmp to columns as:
hello | f | 1

How do i convert those rows to columns?

PS: once i convert rows to columns then only i can assign that row of data to the table1

thanks

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-03 : 04:55:23
You need to use dynamic pivot. Have a look at:
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-04 : 09:41:17
will number of columns be static always?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -