Some RDBMS are providing ISNULL() method to deal with potentially null values. We can use ISNULL() to check or select null values in a database. It is close to IFNULL() in some other databases. Here we are checking few null values.
SELECT ISNULL( null ), ISNULL( 'Tropical' );
first one will return 1 and second one will return 0. Here is another example.
SELECT * FROM Pets WHERE ISNULL(DOB);
Here we are just selecting records with DOB as null. There is another way to do that.
SELECT * FROM Pets WHERE ISNULL(DOB) = 1;
Now we can use it to return some interesting values in SQL server.
SELECT ISNULL( null, 'Cheese' );
Now if first parameter is null then it will return second parameter. It can be used to select some other default value if the selection parameter is null. Now we can use “IS NULL” predicate also to select null or not null value. Let’s assume R is our query, so we can use IS NULL in these many ways.
R IS NULL R IS NOT NULL NOT R IS NULL NOT R IS NOT NULL
Now here is a real world example.
SELECT * FROM Pets WHERE DOB IS NULL;
I hope this article will help you to use ISNULL() and IS NULL to handle null values in SQL. If you have any questions, please write down in comments section.