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
 Nesting

Author  Topic 

sadderson
Starting Member

13 Posts

Posted - 2013-08-15 : 16:59:17
Data

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..

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-08-15 : 17:12:06
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
TG
Go to Top of Page

sadderson
Starting Member

13 Posts

Posted - 2013-08-15 : 18:04:54
Fantastic... did exactly what I wanted...

Scott
Go to Top of Page
   

- Advertisement -