0

Using SQL Server 2014 Management Studio, I've been trying to find a way to convert

Year    Name    Col1    Col2    Col3    Col4    Col5
----------------------------------------------------
2015    ABC   0.24     0.00    0.21    0.79     0.00
2015    XYZ   0.25     0.00    0.00    0.71     0.29

to

Date    Name    Col   Value
---------------------------
2015    ABC    Col1   0.24
2015    ABC    Col2   0.00
2015    ABC    Col3   0.21
2015    ABC    Col4   0.79
2015    ABC    Col5   0.00
2015    XYZ    Col1   0.25
2015    XYZ    Col2   0.00
2015    XYZ    Col3   0.00
2015    XYZ    Col4   0.71
2015    XYZ    Col5   0.29

in a dynamic fashion (i.e. it should work for any table like the first one, with n number of columns)

I've been looking around at general pivot function and doesn't seem to solve my problem.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kamster
  • 127
  • 7
  • You actually need to unpivot the data, not pivot because you are converting columns into rows. – Taryn Dec 09 '15 at 19:43
  • I marked the wrong question as the dupe. I believe [this one](http://dba.stackexchange.com/questions/48393/passing-column-names-dynamically-to-unpivot) should do what you describe, however. – Bacon Bits Dec 09 '15 at 19:47

0 Answers0