Why this query doesn't work? :( I tried to replace nested IF statement "...SET lkey = IF(lkey >= 11, lkey - 5, IF(lkey > 5, lkey + 2,lkey))"
UPDATE pages
SET lkey = CASE lkey WHEN lkey >= 11 THEN
lkey - 5
ELSE
CASE lkey WHEN lkey > 5 THEN
lkey + 2
ELSE
lkey
END
END,
rkey = CASE lkey WHEN lkey >= 11 THEN
rkey - 5
ELSE
CASE rkey WHEN rkey < 11 THEN
rkey + 2
ELSE
rkey
END
END
WHERE rkey > 5 AND
lkey < 12;
The syntax is wrong in this clause (and similar ones)
It's either
or
So in your case it would read:
Check out the documentation (The CASE expression):
http://www.sqlite.org/lang_expr.html
Also, you do not have to use nested CASEs. You can use several WHEN-THEN lines and the ELSE line is also optional eventhough I recomend it