Computers & ProgrammingBackend DevelopmentSQL

SQL ISNULL, NVL, and IFNULL Functions

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top