?
Solved

db2 sql sum a null value as zero.

Posted on 2011-03-07
2
Medium Priority
?
1,302 Views
Last Modified: 2012-06-21
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
Comment
Question by:bobdylan75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 2000 total points
ID: 35057773

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

Author Closing Comment

by:bobdylan75
ID: 35057814
thanks
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question