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.
| Author |
Topic |
|
natg504
Starting Member
14 Posts |
Posted - 2009-02-23 : 11:26:47
|
| I have a table with data similar to this format:clm1 clm2 clm3 clm4 10 20 30 40 50 60 70 NULL 80 90 NULL 100My SQL is something like this:SELECT (clm1 + clm2 + clm3 + clm4) AS TotalClmsI'd like the result to be (ignoring NULLs):TotalClms100180170But instead I get:TotalClms100NULLNULLHow can I fix this?Thanks! |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-02-23 : 11:35:57
|
| SELECT (isnull(clm1, 0) + isnull(clm2, 0) + isnull(clm3, 0) + isnull(clm4, 0)) AS TotalClms(assuming you added the third row incorrectly) |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-02-23 : 11:40:22
|
| SELECT coalesce(clm1, 0) + coalesce(clm2, 0) + coalesce(clm3, 0) + coalesce(clm4, 0) AS TotalClms |
 |
|
|
natg504
Starting Member
14 Posts |
Posted - 2009-02-23 : 12:06:58
|
| Oops! You're right.. I did add incorrectly. Your solution worked though. Thank you! |
 |
|
|
|
|
|