SQL Server: ISNULL Function

 ISNULL function in SQL Server

This SQL Server tutorial 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 Servers (Transact-SQL) is:

ISNULL( expression, alternative_value )

Parameters or Arguments

expression

The value to test whether it is NULL.alternative_valueThe 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 Servers (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 functions examples and explore how to use the ISNULL function in SQL Servers (Transact-SQL).

For example:

SELECT ISNULL(NULL, 'adglob.in');
Result: 'adglob.in'

SELECT ISNULL('adglob.com', 'adglob.in');
Result: 'adglob.com'

SELECT ISNULL(NULL, 45);
Result: 45

SELECT ISNULL(12, 45);
Result: 12

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

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

Leave a Reply