Sql Server Isnull Function

SQL Server: ISNULL Function

In this post explains how to use the ISNULL function in SQL Server (Transact-SQL) with syntax and examples.

Description

In SQL Server (Transact-SQL), the ISNULL function lets you return an alternative value when an expression is NULL.

Syntax

The syntax for the ISNULL function in SQL Server (Transact-SQL) is:

ISNULL( expression, alternative_value )

Parameters or Arguments

expression

The value to test whether it is NULL.

alternative_value

The value to return if the expression is a NULL value.

Note

  • The ISNULL function returns the alternative_value, if the expression is a NULL
  • The ISNULL function returns the expression, if the expression is NOT NULL.

Applies To

The ISNULL function can be used in the following versions of SQL Server (Transact-SQL):

  • SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

Example

Let's look at some SQL Server ISNULL function examples and explore how to use the ISNULL function in SQL Server (Transact-SQL).

For example:

SELECT ISNULL(NULL, 'AODBA.com');
Output: 'AODBA.com'

SELECT ISNULL('mySite.com', 'AODBA.com');
Output: 'mySite.com'

SELECT ISNULL(NULL, 45);
Output: 45

SELECT ISNULL(12, 45);
Output: 12

SELECT ISNULL(NULL, '2014-05-01');
Output: '2014-05-01'

SELECT ISNULL('2014-04-30', '2014-05-01');
Output: '2014-04-30'