Introduction
The ISNULL() function
The COALESCE() function
9. Using conversion with COALESCE ()
The NULLIF() function
Summary

Instruction

Yes, COALESCE() failed. We knew it would. But what if we want to replace a numerical value with a string value? Can we do that? We can, as long as we convert the numerical data type to NVARCHAR:

SELECT
  COALESCE(CAST(Price AS NVARCHAR) , N'--')
FROM Product;

Here, we first converted Price to the NVARCHAR data type using CAST(). Then we directed COALESCE() to replace NULL values with a string. Since NVARCHAR takes letters and numbers, we'll get the result we want.

Exercise

Let's try again. We'll select each product name and launch date, with N'no date' displayed when there is no launch date. Here's the code from the previous exercise. You just need to use CAST() for converting Launchdate to NVARCHAR data type so that COALESCE() works properly.

Stuck? Here's a hint!

Use:

COALESCE(CAST(LaunchDate AS NVARCHAR), N'no date')