Solved

db2 sql sum a null value as zero.

Posted on 2011-03-07
2
1,264 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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

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 (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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