Thursday, September 27, 2012

Working with PIVOT and UNPIVOT using SQL Server

  • I worked with PIVOT and UNPIVOT in SQL Server 2005.It is pretty easy using with them.I used for PIVOT  and UNPIVOT  regularly in my daily T-SQL programming.
PIVOT  is used for splitting one column to multiple column based on the condition.
while UNPIVOT  is used for clubbing multiple columns into as single column.
We can able to combine PIVOT   and UNPIVOT   for cross tab reports.It  minimize the code for writing using CASE statement.Even though CASE statement is more readable am most preferable for Cross tab reports.
Some times CASE Statement is better for multiple aggregate functions.




No comments: