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 |
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-12-12 : 06:11:55
|
| If i want to use the sum function but some of the fields are NULLthe sum returns as NULL ..how can I avoid this ? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-12 : 06:14:09
|
| sum(coalesce(col1,0))+sum(coalesce(col2,0))+...MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-12 : 06:20:22
|
sum(coalesce(col1, 0) + coalesce(col2, 0) + ... ) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-12-12 : 06:21:29
|
| So [CODE]select a ,b,sum(c) as 'TOTAL'[/CODE]becomes [CODE]select a ,b,sum(coalesce(c,0)) as 'TOTAL'[/CODE]? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-12 : 06:22:18
|
shortcut of mine? MadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2007-12-12 : 06:23:53
|
| yes but i was checking that is correct yes ? sum(coalesce(c,0)) as 'TOTAL' ?? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-12 : 06:24:02
|
quote: Originally posted by pazzy11 So [CODE]select a ,b,sum(c) as 'TOTAL'[/CODE]becomes [CODE]select a ,b,sum(coalesce(c,0)) as 'TOTAL'[/CODE]?
If you sum only one column, by default NULL values are omittedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|