SQL Server ISNULL() Function Example

Let’s look at some examples of the ISNULL function in SQL Server. Learning the ISNULL function with examples will help in understanding the concept better.

Example 1

Using the 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 = 'w3wiki';
SELECT ISNULL(@exp, 150);

Output :

w3wiki

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

SQL Server ISNULL() Function

SQL Server ISNULL() function returns the given value if the expression is NULL; otherwise, it returns the expression value.

Similar Reads

ISNULL() Function in SQL Server

The ISNULL() function in SQL Server is used to replace NULL values with a specified replacement value....

Syntax

SQL Server ISNULL() function syntax is:...

SQL Server ISNULL() Function Example

Let’s look at some examples of the ISNULL function in SQL Server. Learning the ISNULL function with examples will help in understanding the concept better....

Important Points About SQL Server ISNULL Function

The ISNULL() function is used to return a specified value if the expression is NULL, otherwise it returns the expression itself. It is used to replace NULL values in expressions or table columns with a meaningful value. It is different from the IS NULL operator, which is used to check if a value is NULL. The ISNULL() function is useful for handling NULL values in queries and providing alternative values when NULL is encountered....

Contact Us