List:General Discussion« Previous MessageNext Message »
From:Baron Schwartz Date:September 5 2007 1:30am
Subject:Re: Editing fields in bulk
View as plain text  
Brian Dunning wrote:
> I have a column where I need to replace all instances of the text 
> "US-Complete" (contained within a long sentence) with "US Complete". 
> There are probably 50 or 100 of them. I'm really scared to do it since I 
> can't risk screwing up that column - what's the correct syntax?

UPDATE tbl SET col=REPLACE(col, 'US-Complete', 'US Complete');

If there are spaces in front and back, perhaps you should add some extra 
insurance to avoid changing 'US-Completely' or 'BUS-Complete' as well:

UPDATE tbl SET col=REPLACE(col, ' US-Complete ', ' US Complete ');

The best insurance is to do a SELECT first to see what will be changed:

SELECT col, REPLACE(col, 'US-Complete', 'US Complete') FROM tbl;

Baron
Thread
Editing fields in bulkBrian Dunning5 Sep
  • RE: Editing fields in bulkHartleigh Burton5 Sep
  • Re: Editing fields in bulkGary Josack5 Sep
  • Re: Editing fields in bulkBaron Schwartz5 Sep
  • Re: Editing fields in bulkMartijn Tonies5 Sep