Sql Syntax for a replacment

tmaususer
tmaususer used Ask the Experts™
on
I have never done a mass update to replace records (newbie) in a table so I am looking for some help with the syntax which I'm sure is easy.
I have a table called Parts. In that table there I have a field name called femail. I have records in that field name for email addresses. So records do not require an email address so they are null values.

For the records they contain multiple email addresses in that field which are all the same. So for example:

Femail
test1@test.com; test2@test.com

So my question is I want to do a mass replacment for the test1@test.com email and replace all of those records with JohnDoe@test.com
So the end result would be where test1@test.com was it should now show:

JohnDoe@test.com; test2@test.com



How would I accomplish this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
UPDATE Parts
SET femail = REPLACE(femail,'test1@test.com','JohnDoe@test.com')
WHERE femail LIKE 'test1@test.com'

Open in new window

Test this command in a development database before running it in Production environment.
PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
WHERE femail LIKE 'test1@test.com%' --<< nb: the percent sign

if the column femail STARTS with test1@test.com than that where clause will work

but:

WHERE femail LIKE '%test1@test.com%'

if the column femail CONTAINS test1@test.com than that where clause will work (but will be slower)

{+edit}
it is usually prudent to use a select query before trialing an update query

e.g.

select *
from parts
WHERE femail LIKE 'test1@test.com%' --<< nb: the percent sign

so you can assess if the filter is getting the right rows.
IT Engineer
Distinguished Expert 2017
Commented:
Thanks Paul. I forgot to add the percentages:
UPDATE Parts
SET femail = REPLACE(femail,'test1@test.com','JohnDoe@test.com')
WHERE femail LIKE '%test1@test.com%'

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
it happens :)

Author

Commented:
Victor the syntax you provided did not change anything
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
What this returns?
SELECT *
FROM Parts
WHERE femail LIKE '%test1@test.com%'

Open in new window

Commented:
--it is a very specific replace " the test1@test.com "

UPDATE Parts
SET femail = REPLACE(femail,'test1@test.com','JohnDoe@test.com')
WHERE femail ='test1@test.com'


also read
"REPLACE"
https://msdn.microsoft.com/en-us/library/ms186862.aspx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial