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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

13 Posts

Posted - 08/15/2013 :  16:59:17  Show Profile  Reply with Quote

Category 1 Category 2 Name Option 3
1 0 Dave no
2 5 Fred no
3 1 Don yes
4 1 Ted no
1 1 Dave yes
2 2 Fred yes

What I need is to total category 1 and category 2 for Name but only add Category 2 if Option 3 is yes..

Flowing Fount of Yak Knowledge

6062 Posts

Posted - 08/15/2013 :  17:12:06  Show Profile  Reply with Quote
perhaps this?

select sum(category1)
       ,sum( case when option3 = 'yes' then category2 else 0 end) as category2
from   yourTable
group by name

Be One with the Optimizer

Edited by - TG on 08/15/2013 17:12:50
Go to Top of Page

Starting Member

13 Posts

Posted - 08/15/2013 :  18:04:54  Show Profile  Reply with Quote
Fantastic... did exactly what I wanted...

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