Skip to content
Advertisement

SQL rotate results from wide to vertical

I would love some help with the best way to capture some column data and rotate it so I can store the column name and numeric value in a temp table.

The results are a single row showing a value for the columns listed here:

I would like to take the above query and rotate the output to look more vertical.

I was trying to use PIVOT / UNPIVOT but could not figure how to make it work for this case.

Any ideas?

Advertisement

Answer

If you are working with SQL Sever then you can use APPLY :

In standard you can use UNION ALL to UNPIVOT the data.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement