Sql Syntax for a replacment

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?
tmaususerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
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.
0
PortletPaulfreelancerCommented:
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.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PortletPaulfreelancerCommented:
it happens :)
0
tmaususerAuthor Commented:
Victor the syntax you provided did not change anything
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
What this returns?
SELECT *
FROM Parts
WHERE femail LIKE '%test1@test.com%'

Open in new window

0
Eugene ZCommented:
--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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.