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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Multiple pivot statement in single query?

Author  Topic 

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2011-08-08 : 11:12:28
Hi All,

I am generatinig report having customised emp column. my sql returing me the out put as below

Emp ID Salary Deduc
10010 2000 100
10011 3500 150
10012 4000 250
10013 1200 100

Is it possible in sql to use multiple pivot (one for Emp ID and salary) and another for Emp ID and Deduc) to get below customised output?

Sal-10010 Sal-10011 Sal-10012 Sal-10013 Ded-10010 Ded-10011 Ded-10012 Ded-10013
2000 3500 4000 1200 100 150 250 100

Please help me out.
T.I.A

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-08 : 13:34:17
i think you need dynamic pivot for this. see

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

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

Go to Top of Page
   

- Advertisement -