ISNULL (Transact-SQL)

ISNULL (Transact-SQL)

Replaces NULL with the specified replacement value.


ISNULL ( check_expression , replacement_value )

Example 1

USE AdventureWorks;
GO
SELECT Description, DiscountPct, MinQty, MaxQty AS ‘Max Quantity’
FROM Sales.SpecialOffer;
GO
==================================================
USE AdventureWorks;
GO
SELECT Description, DiscountPct, MinQty, ISNULL(MaxQty, 0.00) AS ‘Max Quantity’
FROM Sales.SpecialOffer;
GO

If the maximum quantity for a particular special offer is NULL, the MaxQty shown in the result set is 0.00.

ISNULL()

Example 2
USE AdventureWorks;
GO
SELECT AVG(Weight)
FROM Production.Product;
GO
============================================
USE AdventureWorks;
GO
SELECT AVG(ISNULL(Weight, 50))
FROM Production.Product;
GO
It substitutes the value 50 for all NULL entries in the Weight column of the Product table.

ISNULL()