Link to home
Start Free TrialLog in
Avatar of jammy-d0dger
jammy-d0dger

asked on

How to add 2 decimal columns when one of them may be null

Hi experts,

If I have two decimal columns in a table and I want to return the sum of the two columns added together as another column in my resultset, how do I do it when one of the columns 'may' be NULL?

(OPR.refund_product_value + OPR.refund_extra_value) AS refund_total_value

If one of the two values here is NULL, the result is also NULL.

Help appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdd1lan
pdd1lan

SELECT COALESCE(table1.field1,0,table1.field1) + COALESCE(table1.field2,0,table1.field2)  as fieldname
FROM table1
Avatar of jammy-d0dger

ASKER

Perfect, spot on.  Works a treat, thanks for that.