Did you find this useful?
Socialize it today.


SQL ISNULL, NVL, and IFNULL Function

Tuesday, December 13, 2011

tags SQL

The SQL ISNULL function can be used to replace null values in the results of a query with alternate data. The ISNULL function is used by Microsoft SQL. Other SQL platforms, such as Oracle and MySQL use comparable functions such as NVL, IFNULL and COALESCE.

Employees Table

employeeIDemployeeNameage
1000John Smith40
1001Fred White27
1002 53
1003Samuel Williams31


In this example, when we query the employees table, we want to replace null values in the employeeName field with 'Unknown'.


Syntax

SELECT ISNULL(column_name,'value')
FROM Table


Example
SELECT ISNULL(employeeName,'Unknown') as [Employee Name]
FROM employees


Results

Employee Name
John Smith
Fred White
Unknown
Samuel Williams

The SQL ISNULL function can be very helpful when null values need to be replaced in the result set with alternate information.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook