Addition with NULL values

后端 未结 5 776
傲寒
傲寒 2020-12-10 11:00

In a stored procedure (Oracle in my case), I want to add some values to an existing record. Problem is that both the existing value and the value to be added can be null. I

5条回答
  •  时光说笑
    2020-12-10 11:25

    In SQL terms, when adding numbers, a result of NULL means there were no non-null numbers added.

    This suggests that a sensible answer in SQL terms would be

    CASE WHEN A IS NULL AND B IS NULL THEN NULL ELSE ISNULL(A, 0) + ISNULL(B, 0) END

提交回复
热议问题