[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1364
  • Last Modified:

db2 sql sum a null value as zero.

I have a simple query,
a table A that joins on table B
I have to sum one filed of A with one filed of B,
BUT:
If B doesnt match,
I dont want the result filed keep NULL value,
but only A field value.

In example:
if A field is 1 and B field is 1, the result field is 2.

BUT
if A field is 1 and B field is NULL (because it doesn match with A table key)
the result is NULL at the moment,
I would like it results 1.

there a function which transform null value in 0 in order to resolve the issue,
or are there other ways?
thanks



select A.valA, B.valB, A.valA+B.valB as Result from
A left join on A.key=B.key

Open in new window

0
bobdylan75
Asked:
bobdylan75
1 Solution
 
momi_sabagCommented:

select A.valA, B.valB, A.valA+ coalesce(B.valB,0) as Result from
A left join on A.key=B.key
0
 
bobdylan75Author Commented:
thanks
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now