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
 General SQL Server Forums
 New to SQL Server Programming
 need some direction

Author  Topic 

redhooked
Starting Member

2 Posts

Posted - 2008-04-15 : 11:54:58
this is a seemingly simple query, but i've been googling around for a while and haven't been able to come up anything, probably because i simply can't explain what I'm trying to do

can someone please point me in the right direction? using sql server 2005.

tbl_vendorprice looks like:


id vend price
1 A 2.00
1 B 3.00
2 A 4.00
2 B 3.50
3 A 8.00
3 B 8.50


and this is what i want as a result


id vendA VendB
1 2.00 3.00
2 4.00 3.50
3 8.00 8.50

thanks

David

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-15 : 12:02:18
[code]SELECT id,
SUM(CASE WHEN vend='A' THEN price ELSE 0 END) AS vendA,
SUM(CASE WHEN vend='B' THEN price ELSE 0 END) AS vendB
FROM YourTable
GROUP BY id[/code]
Go to Top of Page

redhooked
Starting Member

2 Posts

Posted - 2008-04-15 : 12:43:29
perfect. thank you
Go to Top of Page
   

- Advertisement -