Pivot Tables in Sql Server


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 name,MONTH,salary
FROM test

) p
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

Author: Pavan

I am asp.net developer have good knowledge of Asp.net ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API ASP.net with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies

One thought on “Pivot Tables in Sql Server”

Comments are closed.