PIVOT and UNPIVOT in SQL Server can be used in some amazing ways. Using some real world examples, we are going to show you what can be done.
Each stage gets a bit more complex, so step through each if you can.
Turn columns into rows, for instance useful when you need to break up a large table with months as columns.
Turn rows into columns, great for displaying data on an SSRS report.
Use dynamic SQL to extend this function to any unknown column names.
Combine the two to re-build a table without a mass of CASE statements, or transfer data in a neutral form.