473,503 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT NULL VALUES AS ZERO

Hi

I'm using DB2 and I'm trying to pull information from a table.

I've tried every function possible (IFNULL,COALESCE,CASE) to get a zero
every time the column is NULL.

The thing is I don't know if they are actually nulls or if they are
something like ' '

How can I select blank columns as zero?

Jan 24 '06 #1
2 32924

da********@gmail.com wrote:
Hi

I'm using DB2 and I'm trying to pull information from a table.

I've tried every function possible (IFNULL,COALESCE,CASE) to get a zero
every time the column is NULL.

The thing is I don't know if they are actually nulls or if they are
something like ' '

How can I select blank columns as zero?


Not sure what you are trying to do. Does this come close?

coalesce(nullif(val,''),'0')

Note that "zero" has to be char instead of int. Example:

db2 "with t (val) as (values (' '),(' a '),('b ')) select
coalesce(nullif(val,''),'0') from t"
1
---
0
a
b

HTH
/Lennart

Jan 24 '06 #2
IFNULL is probably not what you want here.

COALESCE retrieves the first NOT NULL value in its list. So, for
example, if you have a TABLE that includes amounts and NULLs, and want
NULLs to be represented by zeros:

SELECT COALESCE(amount, 0) FROM table

CASE can be used, but it may not be needed.

If COALESCE did not work for you, please provide the SQL statement
used, so we can take a better look.

B.

Jan 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
12190
by: Joshua Ruppert | last post by:
A section of the documentation for the isSet() function states: Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant. Where would you encounter a NULL byte? Is a null...
1
3023
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
9
5635
by: madsgormlarsen | last post by:
Hi I need to test a field(colum) in a SQL database for for NULL values, and have done so in this way. $query = "SELECT j FROM Andersen"; $result = mysql_query($query, $link_id); $query_data...
2
18020
by: C. Lo | last post by:
Hi I have a situtation where a query returns a table in which some of the values are null. When I sort the results, the null values are treated as greater than the other numerical results. Is it...
8
12519
by: manning_news | last post by:
Using SQL2000. According to Books Online, the avg aggregrate function ignores null values. ((3+3+3+3+Null)/5) predictably returns Null. Is there a function to ignore the Null entry, adjust the...
6
5254
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
3
11468
by: John | last post by:
I've read several prior posts in this group about using nz() to convert null values to zero; however, I'm not sure how/where to implement this function in my crosstab query. The crosstab query...
3
4229
by: Alexander Pucher | last post by:
Hi, given a table with some data, e.g. some monthly measures. Some of the measures are missing though. id m1 m2 m3 m4 m5 .... m12...
10
8996
by: Toby Gallier | last post by:
Hello! I have a form that is calculating averages as follows: " =(NZ()+Nz()+Nz())/3 " However I need to now adjust for null values , so for example if value2 is null I would then need to...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.