SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL output format issues
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sridhar3004
Starting Member

31 Posts

Posted - 07/27/2012 :  07:47:55  Show Profile  Reply with Quote
I've the following query

Name Group Expense Budget Variation
Sridhar Conveyance 1500 2000 500
Travel Allownce 100 200 100
Rajesh Conveyance 700 2000 1300
Travel Allownce 50 200 150

I want the final output to be as follows

Name ConveyanceExpense ConveyanceBudget ConveyanceVariation TravelAllownceExpense TravelAllownceBudget TravelAllownceVariation
Sridhar 1500 2000 500 100 200 100
Rajesh 700 2000 1300 50 200 150

ANy help is appreciated

Thanks


visakh16
Very Important crosS Applying yaK Herder

India
47036 Posts

Posted - 07/27/2012 :  10:30:22  Show Profile  Reply with Quote

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  TravelAllownceVariation
FROM tablename
GROUP BY Name


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000