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 queries

Author  Topic 

mathiyazhagan.sekar@gmail
Starting Member

11 Posts

Posted - 2008-06-02 : 05:08:13
Hi ALL,
I am not able to understand the concept of "PIVOT" queries.I am not able get when and how to use this types of query.Help Me.



Cheers,
Mathi
India.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 05:10:46
You maen the new PIVOT statement in SQL 2005? Have you had a look at books online? It has a good example with explanation.
Another example can be found here too:-

http://geekswithblogs.net/lorint/archive/2006/08/04/87166.aspx
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-02 : 05:11:15
PIVOT is used to

1) denormalize a table
2) Make CROSSTAB or PIVOT queries



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-06-02 : 05:12:02
quote:
Originally posted by mathiyazhagan.sekar@gmail

Hi ALL,
I am not able to understand the concept of "PIVOT" queries.I am not able get when and how to use this types of query.Help Me.



Cheers,
Mathi
India.



Read books online for pivot. Generally we use PIVOT operator for transforming rows into columns i.e., for producing cross tab reports while getting output.
To understand the use of PIVOT go through the below example

declare @temp table ( id int ,item varchar(500),yearofsale int)
insert into @temp values(1,'t.v',2000)
insert into @temp values(2,'radio',2000)
insert into @temp values(3,'camera',2001)
insert into @temp values(4,'mobile',2002)
insert into @temp values(5,'car',2003)
select * from @temp ------INPUT
select * from
(select yearofsale ,id,item from @temp) a
pivot
(
count(id) for yearofsale in ([2000],[2001],[2003],[2002])
)b
Go to Top of Page
   

- Advertisement -