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)
 JOIN HELP
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mkswanson
Starting Member

21 Posts

Posted - 02/08/2013 :  05:06:24  Show Profile  Reply with Quote
I have a table that contains info:

id, date, amount, amountType

amountType has 3 valid values (1, 2, 3)

I would like to create a statement that returns

id, date, amount (where amount type = 1), amount (where amount type = 2) amount (where amount type = 3)

In reality, the table and data are more complex, but I can't get the simpler scenario to work. This isn't really that difficult, is it?

Thanks for any input...

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 02/08/2013 :  05:19:19  Show Profile  Reply with Quote

SELECT *
FROM table t
PIVOT (SUM(amount) FOR amountType IN ([1],[2],[3]))p


------------------------------------------------------------------------------------------------------
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.12 seconds. Powered By: Snitz Forums 2000