I\'d like to avoid having many checks like the following in my code:
myObj.someStringField = rdr.IsDBNull(someOrdinal)
? string.
You can easily define such function and use it then:
ifnull <- function(x,y) {
if(is.na(x)==TRUE)
return (y)
else
return (x);
}
or same minified version:
ifnull <- function(x,y) {if(is.na(x)==TRUE) return (y) else return (x);}
For the equivalent of NVL() and ISNULL() use:
IFNULL(column, altValue)
column
: The column you are evaluating.
altValue
: The value you want to return if 'column' is null.
Example:
SELECT IFNULL(middle_name, 'N/A') FROM person;
*Note: The COALESCE() function works the same as it does for other databases.
Sources:
Use IS NULL
or IS NOT NULL
in WHERE-clause instead of ISNULL() method:
SELECT myField1
FROM myTable1
WHERE myField1 IS NOT NULL
Try this
ifnull(X,Y)
e.g
select ifnull(InfoDetail,'') InfoDetail; -- this will replace null with ''
select ifnull(NULL,'THIS IS NULL');-- More clearly....
The ifnull()
function returns a copy of its first non-NULL argument, or NULL if both arguments are NULL. Ifnull()
must have exactly 2 arguments. The ifnull()
function is equivalent to coalesce()
with two arguments.
If there is not ISNULL()
method, you can use this expression instead:
CASE WHEN fieldname IS NULL THEN 0 ELSE fieldname END
This works the same as ISNULL(fieldname, 0)
.
IFNULL
, see here: http://www.sqlite.org/lang_corefunc.html#ifnull
no brackets around the function