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.
Hi allnot exactly sure what I am supposed to do here if it is pivot or unpivot. I have a data set where all columns after the first column need to pivot but the first column then needs to relate the value it has against the original and show the duplicate value, as shown below if you don't understand the requirement:
Number New Col1 Value ====== ======= ======= 1 column1 20 1 column2 60 1 column3 302 column12 colunm2 122 column3 8.........
Any thoughts on the steps I need to take would be most helpful.G
Grifter
Constraint Violating Yak Guru
274 Posts
Posted - 2011-09-16 : 06:14:09
I think it was unpivot I had to use.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-09-16 : 12:20:21
its indeed unpivot
SELECT Number,[New Col],[Value]FROM (SELECT Number,ISNULL(Column1,'') AS Column1,ISNULL(Column2,'') AS Column2,ISNULL(Column3,'') AS Column3FROM Table)tUNPIVOT([Value] FOR [New Col1] IN ([Column1],[Column2],[Column3]))u
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/