Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 pivot table

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-12-24 : 00:44:47
hi team, please tell me what is pivot table, and please give a example
where this is use.

challenge everything

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-24 : 00:54:37
are you asking about pivot table in excel or PIVOT in sql server?
Both cases concept is same. You group results in a table based on one or more values in a field and show them in different columns ie effectively turning rows of tables to columns.

As an example see this simple
case

StudentName Subject Marks
-------------------------------------
Stud1 Subj1 50
Stud1 Subj2 27
Stud1 Subj3 30
Stud2 Subj2 48
Stud2 Subj3 33
Stud3 Subj1 42
Stud3 Subj4 47
Stud3 Subj2 34


now if you've do the pivot based on subject field you will get result as

StudentName Subj1 Subj2 Subj3 Subj4
----------------------------------------------
Stud1 50 27 30
Stud2 48 33
Stud3 42 34 47


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-12-24 : 02:46:12
thanks a lot. please write query for the same scenario

challenge everything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-24 : 02:51:21
hmm... why dont you try it yourself first

start with learning PIVOT operator

http://www.tsqltutorials.com/pivot.php

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-12-24 : 02:52:34
that is too useful for me.

challenge everything
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-27 : 08:12:40
This is for Dynamic PIVOT
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -