Return to Snippet

Revision: 18064
at September 22, 2009 09:11 by iroybot


Initial Code
UPDATE `table` SET `table`.`fieldname` = replace(`fieldname`, 'search_value', 'replace_with') 
WHERE `table`.`firstcondition_field` = 'firstcondition_value'
AND `table`.`secondcondition_field` = 'secondcondition_value'
AND so on...

Initial URL

                                

Initial Description
as a note to self... in order to find it laters...

This will only alter the value of fieldname if the conditions in the WHERE clause are met. With replace we only replace a certain string within fieldname with the replace_with string

Initial Title
Conditional String Replace

Initial Tags
replace, update

Initial Language
MySQL