| Author |
A little SQL help with SUM()
|
Paul Duer
Ranch Hand
Joined: Oct 10, 2002
Posts: 98
|
|
Hi guys, I have query with a sum() in it, on a DB2 7.0 box. One of my sum() records returns a null because there are no values to add, but I want it to send back a zero so that it gets printed on a report. I tired using CASE WHEN to catch the null and print the '0' but I get an erorr, any ideas?
|
 |
Anurag Gupta
Ranch Hand
Joined: Dec 13, 2001
Posts: 40
|
|
|
In your Query you could use an equivalent of Decode in Oracle, if there is any in DB2.
|
Anurag Gupta
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
|
|
Paul, How are you getting a null? Are you using rs.getString(column)? rs.getInt(column) returns 0 if the value is null and the expected value otherwise.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Braj Prasad
Greenhorn
Joined: Apr 08, 2002
Posts: 16
|
|
Try using the following case statement : select col1, col2, case when sum(colName) is NULL then 0 elsesum(colName) end as Total from table.
|
 |
 |
|
|
subject: A little SQL help with SUM()
|
|
|