[thelist] SQL partial string replace

David McCreath mccreath at kadmium.net
Fri Jan 10 15:06:00 CST 2003


> -----Original Message-----
> From: rudy
>
> > I need to change the domain name for a bunch of email
> addresses in a
> > MySQL database (asd.k12.ak.us -> asdk12.org)
>
> UPDATE yourtable
>   SET emailcolumn
>      = REPLACE(emailcolumn,'asd.k12.ak.us','asdk12.org')
>          WHERE emailcolumn like '%asd.k12.ak.us%'
>
> http://www.mysql.com/doc/en/String_functions.html#IDX1189
>
> the WHERE condition will choose the rows to update -- without it,
> you will update every row in the table (most of them with the same
value they were)

Rudy, you rock. Somehow in all my searching yesterday I never came
across that page.

Thanks, man.

David




More information about the thelist mailing list