Using CASE in UPDATE

suggest change

Example of price increases. A simple CASE never matches a NULL ItemId (equality with NULL is unknown), so that row uses ELSE and the price is unchanged:

UPDATE ItemPrice
SET Price = Price *
  CASE ItemId
    WHEN 1 THEN 1.05
    WHEN 2 THEN 1.10
    WHEN 3 THEN 1.15
    ELSE 1.00
  END

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents