Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 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

6065 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  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000