BobBarker_99
asked on
SQL - Adding two select statements, handling NULL
Here is my problem.
I have a query like: SELECT (SELECT SUM (fld1) FROM tbl1 + SELECT SUM9fld1 FROM tbl2)
This works fine, except when 1 (or both) of the SELECT SUM statements returns NULL. How can I make it return a 0 instead of a NULL so it doesnt mess up my calculation?
Thanks
I have a query like: SELECT (SELECT SUM (fld1) FROM tbl1 + SELECT SUM9fld1 FROM tbl2)
This works fine, except when 1 (or both) of the SELECT SUM statements returns NULL. How can I make it return a 0 instead of a NULL so it doesnt mess up my calculation?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
select SUM(COALESCE(fldAmount, 0)) FROM tblPaymentOut WHERE fldContactRef = @ContactRef
Is still returning NULL
Is still returning NULL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Small Change in mathewspatrick's comment:
SELECT (SELECT SUM(COALESCE(fld1,0)) FROM tbl1)
+ (SELECT SUM(COALESCE(fld1,0)) FROM tbl2) as sum_total
ASKER
the result is still NULL