[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

db2 sql sum a null value as zero.

Posted on 2011-03-07
2
Medium Priority
?
1,339 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

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 (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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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