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.
| Author |
Topic |
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2009-03-19 : 00:53:25
|
| Hi,i have a list of training names which i want to display horizontally for reporting purpose.can i do it with PIVOT? can anyone explain where will PIVOT be appropriate and why?the data is:training_nameABCDEFGHi want it as :A|B|C|D|E|F|G|H - columns of my reportthanks in advance.... |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-19 : 02:23:46
|
| This is My table dataYear Quarter Amount1990 1 1.1001990 2 1.2001990 3 1.3001990 4 1.4001991 1 2.1001991 2 2.2001991 3 2.3001991 4 2.4001991 4 2.4001990 4 2.400with out using Pivot:-Select Year, sum( case Quarter when 1 then Amount else 0 end) as Q1, sum( case Quarter when 2 then Amount else 0 end) as Q2, sum( case Quarter when 3 then Amount else 0 end) as Q3, sum( case Quarter when 4 then Amount else 0 end) as Q4from Pivot1Group By Year |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-19 : 02:24:18
|
| Using Pivot:-Select Year,[1] as Q1,[2] as Q2,[3] as Q3,[4] as Q4from ( select * from Pivot1) as Ppivot( SUM(Amount) for Quarter IN ( [1],[2],[3],[4] ) ) as pc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-19 : 12:50:27
|
quote: Originally posted by mrm23 Hi,i have a list of training names which i want to display horizontally for reporting purpose.can i do it with PIVOT? can anyone explain where will PIVOT be appropriate and why?the data is:training_nameABCDEFGHi want it as :A|B|C|D|E|F|G|H - columns of my reportthanks in advance....
pivot should have a field for aggregation. do you've any other info which you need to aggregate upon based on row values? |
 |
|
|
|
|
|
|
|