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 |
sridhar3004
Starting Member
34 Posts |
Posted - 2012-07-27 : 07:47:55
|
I've the following queryName Group Expense Budget VariationSridhar Conveyance 1500 2000 500 Travel Allownce 100 200 100Rajesh Conveyance 700 2000 1300 Travel Allownce 50 200 150I want the final output to be as followsName ConveyanceExpense ConveyanceBudget ConveyanceVariation TravelAllownceExpense TravelAllownceBudget TravelAllownceVariationSridhar 1500 2000 500 100 200 100Rajesh 700 2000 1300 50 200 150ANy help is appreciatedThanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-27 : 10:30:22
|
[code]SELECT Name,SUM(CASE WHEN Group = 'Conveyance' THEN Expense ELSE 0 END) AS ConveyanceExpense,SUM(CASE WHEN Group = 'Conveyance' THEN Budget ELSE 0 END) AS ConveyanceBudget,SUM(CASE WHEN Group = 'Conveyance' THEN Variation ELSE 0 END) AS ConveyanceVariation,SUM(CASE WHEN Group = 'Travel Allownce' THEN Expense ELSE 0 END) AS TravelAllownceExpense,SUM(CASE WHEN Group = 'Travel Allownce' THEN Budget ELSE 0 END) AS TravelAllownceBudget,SUM(CASE WHEN Group = 'Travel Allownce' THEN Variation ELSE 0 END) AS TravelAllownceVariationFROM tablenameGROUP BY Name[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|