SQL Server Interview Question #57

What is ISNULL() and how is it used?

SELECT, Filtering, Sorting & Built-in Functions Mid-Level Intermediate

Detailed Explanation

ISNULL(check_expression, replacement_value) is a SQL Server function that returns the replacement when the first expression is NULL; otherwise it returns the original value.

It is convenient for SQL Server-specific code, but data-type behavior matters because the returned type is generally based on the first argument. It should not be used blindly in predicates because wrapping an indexed column in a function can affect SARGability.

Code Example

SELECT Id,
       Name,
       ISNULL(Discount, 0) AS Discount
FROM dbo.Products;