Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a split function tat splits comma seperated values.After splitting the values are say123Would like to change the rows to columns dynamically
col1 col2 col31 2 3
If it is 12output should be
col1 col2 1 2
Thanks for any help
bklr
Master Smack Fu Yak Hacker
1693 Posts
Posted - 2009-06-17 : 07:52:04
see this link it may usefulhttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Nageswar9
Aged Yak Warrior
600 Posts
Posted - 2009-06-17 : 08:06:26
Hi, Try this once,
declare @temp table ( id int)insert into @Temp select 1insert into @Temp select 2insert into @Temp select 3select [1] as col1,[2] as col2,[3] as col3 from(select * from @temp ) tpivot ( max(id) for id in ( [1],[2],[3])) t1
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-06-17 : 10:26:37
quote:Originally posted by Nageswar9 Hi, Try this once,
declare @temp table ( id int)insert into @Temp select 1insert into @Temp select 2insert into @Temp select 3select [1] as col1,[2] as col2,[3] as col3 from(select * from @temp ) tpivot ( max(id) for id in ( [1],[2],[3])) t1
you need to do this dynamically as you're not sure of values in column id. see link posted by bklr