Instruction
Now we will learn a useful SQL Server function: ISNULL(). It replaces NULL with a given value, and it looks like this:
ISNULL(expression, replacement)
It takes two arguments:
- expression is where SQL will look for
NULLs.This argument can be a string, column name, or any other expression. - replacement is what you want to replace all the
NULLs in the expression with.
Study the example below:
SELECT ISNULL(Type, N'unknown') AS Type FROM Product;
This query searches the Type column in the Product table for NULLs. When it finds one, it replaces it with N'unknown'.
Ready to practice?
Exercise
Some products haven't been assigned a category. Select each product's name and category from the Product table. Name the second column Category, and put a N'---' string wherever there is a NULL.
Stuck? Here's a hint!
Use ISNULL() with the Category column and a N'---' string.



