Today i just used Unpivot Functionality of SQL Server and i want to share with you guys.
What is Pivot and Unpivot ?
You can use the PIVOT and UNPIVOT relational operators to change a table-valued expression into another table. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output. UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values.
Here is the simple fiddler for the same : http://sqlfiddle.com/#!3/e32bd/1
What is Pivot and Unpivot ?
You can use the PIVOT and UNPIVOT relational operators to change a table-valued expression into another table. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output. UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values.
Here is the simple fiddler for the same : http://sqlfiddle.com/#!3/e32bd/1