Open In App

ISNULL() Function in SQL Server

Last Updated : 21 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

ISNULL() :

This function in SQL Server is used to return the value given, in case the stated expression is NULL. Moreover, in case the given expression is not NULL then it returns the stated expression.

Features :

  • This function is used to find the given value, in case the expression given is NULL.
  • This function is used to find the given expression, in case the expression given is not NULL.
  • This function comes under Advanced Functions.
  • This function accepts two parameters namely expression, and value.

Syntax :

ISNULL(expression, value)

Parameter :

This method accepts two parameters.

  • expression –
    The specified expression which is to be checked if it’s NULL or not.
  • value –
    The specified value which is to be returned, in case the expression is NULL.

Returns :

It returns the value given, in case the stated expression is NULL else it returns the stated expression if the given expression is not NULL.

Example-1 :

Using ISNULL() function and getting the output.

SELECT ISNULL('gfg', 'Geeks');

Output :

gfg

Here, the expression is returned as the given value is not NULL.

Example-2 :

Using ISNULL() function and getting the output.

SELECT ISNULL(NULL, 'Geeks');

Output :

Geeks

Here, the expression is NULL so, the specified value is returned as output.

Example-3 :

Using ISNULL() function and getting the output using a variable.

DECLARE @exp VARCHAR(50);
SET @exp = 'geeksforgeeks';
SELECT ISNULL(@exp, 150);

Output :

geeksforgeeks

Example-4 :

Using ISNULL() function and getting the output using variables.

DECLARE @exp VARCHAR(50);
DECLARE @val VARCHAR(50);
SET @exp = NULL;
SET @val = 'GFG';
SELECT ISNULL(@exp, @val);

Output :

GFG

Application :

This function is used to find the value given, in case the stated expression is NULL else it finds the stated expression if the given expression is not NULL.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads