Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The ISNULL() function
The COALESCE() function
12. Using COALESCE() with multiple parameters
The NULLIF() function
Summary

Instruction

Good job! The last thing you should know about COALESCE() is that it can take more than two arguments. It will simply look for the first non-NULL value in the list and return it.

SELECT
  COALESCE(Name, CAST(Id AS NVARCHAR), N'n/a')
FROM Product;

The above function will show a product name. If the name is unknown, it will show the product ID instead. If both the name and ID are unknown, it will simply show N'n/a'.

Exercise

Show each product's name and type. When the type is unknown, show the category. If the category is missing too, show N'No clue what that is'. Name the column Type.

Stuck? Here's a hint!

Use:

COALESCE(Type, Category, N'No clue what that is')