SQL Server ISNULL() Function

The ISNULL() function in SQL Server provides a way to handle potential NULL values in your data. It allows you to replace NULL values with a specified value, making your data cleaner and easier to work with.



ISNULL(): Definition and Usage

NULL values can sometimes cause issues in your queries or applications. ISNULL() solves this by letting you substitute a NULL with a value you choose. If the expression isn't NULL, the function simply returns the expression's original value.

Syntax

Syntax

ISNULL(expression, value)
      

Parameter Values

Parameter Description
expression The expression you are checking for NULL. This is required.
value The value to return if the expression is NULL. This is required.

Examples

Replacing a NULL Value

This example replaces a NULL with the string 'W3Schools.com'.

Syntax

SELECT ISNULL(NULL, 'W3Schools.com');
      
Output

W3Schools.com
      

Handling a Non-NULL Value

If the expression isn't NULL, the original value is returned.

Syntax

SELECT ISNULL('Hello', 'W3Schools.com');
      
Output

Hello
      

Replacing NULL with a Number

Replacing a NULL with a numeric value.

Syntax

SELECT ISNULL(NULL, 500);
      
Output

500