How do I use a MySQL Update set case statement with a where clause ?

June 29, 2009 - 9:28 pm

I have been trying to figure out the correct sytnax for this for ages and was wondering if anyone could help me out ? The statement works fine, without the where clause, unfortunately I need that where clause to make the statement usefull at a few points in my application.

update tableName
SET value=CASE
WHEN value+1>100 THEN 100
ELSE value+1
WHERE value_enabled<>0
END;

update tableName
SET value=CASE
WHEN value+1>100 THEN 100
ELSE value+1 END
WHERE value_enabled<>0;

One Response to “How do I use a MySQL Update set case statement with a where clause ?”

  1. 14Me14U Says:

    update tableName
    SET value=CASE
    WHEN value+1>100 THEN 100
    ELSE value+1 END
    WHERE value_enabled<>0;
    References :

Leave a Reply