You need to repeatedly name the text Replace:
Update ... Set texts.message = Replace( Replace( Replace( texts.message, 'thx ', 'thanks ' ) , ' u ', ' you ') , ' r ', ' are ')
EDIT Given that you said that you have many replacements, you will need to do this in a cursor with several calls to UPDATE statements. Something like (I have not tested this at all, so be careful):
Create Temporary Table ReplaceValues ( BeforeText varchar(100) not null , AfterText varchar(100) not null ) Insert ReplaceValues(BeforeText, AfterText) Values('thx ', 'thanks ') Insert ReplaceValues(BeforeText, AfterText) Values(' u ', ' you ') Insert ReplaceValues(BeforeText, AfterText) Values(' r ', ' are ') DECLARE done int DEFAULT(0) DECLARE BeforeValue varchar(100); DECLARE AfterValue varchar(100); DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; DECLARE ReplaceList CURSOR FOR Select BeforeText, AfterText From ReplaceValues; OPEN ReplaceList; REPEAT If NOT done THEN FETCH ReplaceList INTO BeforeValue, AfterValue; Update texts Set texts.message = REPLACE(texts.message, BeforeValue, AfterValue); END IF UNTIL done END REPEAT; CLOSE ReplaceList;
You can translate all this into a procedure so that you can call it later.
Thomas
source share