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 2005 Forums
 Transact-SQL (2005)
 JOIN HELP

Author  Topic 

mkswanson
Starting Member

21 Posts

Posted - 2013-02-08 : 05:06:24
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

52326 Posts

Posted - 2013-02-08 : 05:19:19
[code]
SELECT *
FROM table t
PIVOT (SUM(amount) FOR amountType IN ([1],[2],[3]))p
[/code]

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

Go to Top of Page
   

- Advertisement -