I have a list of emails. I want to change all of them to test emails for my test system e.g. [email protected] to [email protected]. I don't want to use actual emails as it will create problems. Is it possible to change all emails at once in a single query or stored procedure.
Step 1: Launch SQL Server Management Studio and connect to the SQL Server instance where you want to change the details of a mail account. Expand the Management folder, go to Database Mail and right click, then select "Configure Database Mail". A list of options will appear as shown in the below screenshot.
SQL Server REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.
I tried this and it worked perfectly.
UPDATE myTable SET UserEMail =
(SELECT SUBSTRING(UserEMail, 0, PATINDEX('%@%',UserEMail)) + '@example.org'
from myTable U WHERE U.UserID = myTable.UserID)
This one works for me:
UPDATE [TABLE] [EMAIL] = REPLACE([EMAIL], '@company.com', '@test.com')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With