I have a table with 30 columns and I want to easily unpivot ALL columns. I understand I can use this strategy:
SELECT col, value
INTO New_Table
FROM
(SELECT * FROM Test_Data) p
UNPIVOT
(value FOR col IN (Column_Name1, Column_Name2... Column_Name30)) as unpvt
This is how my data comes in:
Column_Name1 Column_Name2 Column_Name3
Value11 Value21 Value31
Value12 Value22 Value32
Value13 Value23 Value33
This is how I want to store it in the new table:
New_Column1 New_cloumn2
Column_Name1 Value11
Column_Name1 Value12
Column_Name1 Value13
Column_Name2 Value21
...
But there must be an easier way than typing in the 30 column names.
Thanks in advance.