0

Could you help me on my probmlem.

Here are the sample data.

ID  Name    Value1      Value2     Value3
1   x       12345       123435     1234567890
2   y       12312313    1234567890  

How can i convert it to this

X          Y
12345      123435
12312313   1234567890
1234567890

Thanks.

  • 1
    Possible duplicate of [Efficiently convert rows to columns in sql server](http://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server) – Paul Hunt Feb 01 '16 at 10:42

1 Answers1

0

First unpivot the data and then pivot the data to get the desired output. Don’t forget to accept and rate the answer if found helpfull.

select * from
(
select * from
(
select *,row_number() over (partition by name order by id) as rn
from tableA
) as a
unpivot
(
val for col in (value1,value2,value3)
) as pvt
) as b
pivot
(max(val) for name in (x,y)) as pvt
sam
  • 1,242
  • 3
  • 12
  • 31