...

View Full Version : cycling values on update, null



BubikolRamios
03-27-2009, 03:08 AM
update table set field =
(SELECT CASE field
when null then 1
when 1 then 2
else null end)


does not work , because null != null inside "case when". That is allso stated in user comments in documentation for Case.

Any other suggestion how to do this ?

Old Pedant
03-28-2009, 07:09 AM
A couple of alternatives.



update table set field =
( CASE WHEN field IS NULL THEN 1
WHEN field = 1 THEN 2
ELSE null END )

(No SELECT needed, by the by.)

Or:


UPDATE table SET field = IF(field IS NULL, 1, IF(field = 1, 2, null) )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum