IBM® Informix® 12.10

CASE expression to update a column

The CASE expression allows a statement to return one of several possible results, depending on which of several condition tests evaluates to TRUE.

The following example shows how to use a CASE expression in an UPDATE statement to increase the unit price of certain items in the stock table:
UPDATE stock
   SET unit_price = CASE
      WHEN stock_num = 1 
      AND manu_code = "HRO"
      THEN unit_price * 1.2
      WHEN stock_num = 1 
      AND manu_code = "SMT"
      THEN unit_price * 1.1
      ELSE 0
      END

You must include at least one WHEN clause within the CASE expression; subsequent WHEN clauses and the ELSE clause are optional. If no WHEN condition evaluates to true, the resulting value is null.


Examples exchange | Troubleshooting

To find the PDF, see Publications for the IBM Informix 12.10 family of products.
For the release notes, documentation notes, and/or machine notes, see the Release Notes page.