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

Instruction

You can also use COALESCE() in calculations:

SELECT
  COALESCE(Price, 0) * 1.05
FROM Product;

The above query will return each product's price times 1.05 (if there's a price value) or a zero if the price is NULL.

Exercise

The company is giving a 10% discount on all prices. Show the names of all products, their current price, and the new discounted price. Name the new column NewPrice. If there is no price, show 0.0 in the NewPrice column.

Stuck? Here's a hint!

You can use the following piece of code to get the right price:

COALESCE(Price * 0.9, 0.0)