Open In App

ISNULL() Function in SQL Server

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 :

Syntax :



ISNULL(expression, value)

Parameter :

This method accepts two parameters.

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.

Article Tags :
SQL