A Pivot Table can automatically sort, count, and total the data stored in one table or spreadsheet and create a second table displaying the summarized data. The PIVOT operator turns the values of a specified column into column names, effectively rotating a table.
Table structure with table test:
The Month colums contain the month number from 1 to 12.By the help of pivot table we can convert rows data into columns.
Pivot Sql query:
—————————————————————–
SELECT *
FROM
(
SELECT name,MONTH,salary
FROM test) p
PIVOT
(
sum (salary)
FOR [month]
IN ([1], [2], [3],[4], [5], [6],[7],[8],[9],[10],[11],[12])
) AS pvt;
——————————————————————
Result displayed by above query :
I think you can understand the working of pivot table through above example
Very nice article. I really enjoyed it reading. And it also cleared lot of my doubts about Pivot tables in SQL Server. Check this helpful link too it also explained very well on Pivot tables in SQL Server…..
http://www.mindstick.com/Blog/163/Pivot%20tables%20in%20SqlServer%202005%202008