TULMER 0 Posted November 1, 2017 Report Share Posted November 1, 2017 I need to update over 400 email address in a table in the database. I need to keep the first half of the email address and change everything after the '@' symbol. Example: FROM: john.doe@oldname.com -- TO: john.don@newcompanyname.com Is there any easy way? Quote Link to post Share on other sites
Ingolme 1,019 Posted November 1, 2017 Report Share Posted November 1, 2017 If you're using MySQL, it has a replace() function https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace It would look something like this: UPDATE `table` SET `field` = REPLACE(`field`, 'oldname.com', 'newcompanyname.com') Do not copy and paste that code because you might ruin your whole table. I haven't tested it to see if it does exactly what I expect it to, so you should run it on a test table and tweak the code if necessary. If you're not using MySQL then you'll need to loop through all the records, process them in a server-side language and then update them. Quote Link to post Share on other sites
TULMER 0 Posted November 1, 2017 Author Report Share Posted November 1, 2017 didn't work -- only replaces complete email address with the field name: UPDATE cicntp SET cnt_email = REPLACE ('cnt_email', 'oldname.com', 'newcompanyname.com') WHERE (cnt_email LIKE '%@oldname.com') ___ results are email address goes to "cnt_email" and nothing more. Quote Link to post Share on other sites
Ingolme 1,019 Posted November 1, 2017 Report Share Posted November 1, 2017 Don't put the field name in quotes, that's telling it to use the field's name as a string. Use backticks for field names. `cnt_email` Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.