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.
Contact Us