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
 Multiple inputs in one row

Author  Topic 

learzbu
Starting Member

27 Posts

Posted - 2014-10-03 : 04:44:20
Is there anyway to get a sum of values from the below sample where Code=A?

Code1 Code2 Code3 Val1 Val2 Val3
A A B 1 5 8
B A B 5 6 2

Desired Result

Val = 12

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-03 : 09:08:53
select sum(case when code1 = 'A' then code1 end +
case when code2 = 'A' then code2 end +
case when code3 = 'A' then code3 end)
from ...
Go to Top of Page
   

- Advertisement -