Replace email domain with example.com in SQL
Just a little snippet which updates emails.
DECLARE @var varchar(50)
SET @var = 'abc@exe.com';
SELECT
@var as 'Original',
SUBSTRING(@var, CHARINDEX('@', @var), LEN(@var) - CHARINDEX(@var, '@')) as 'ToBeReplaced',
REPLACE(@var, SUBSTRING(@var, CHARINDEX('@', @var), LEN(@var) - CHARINDEX(@var, '@')), '@example.com') as 'Replacement';
You can use this in an update statement...
Eg:
UPDATE MyTable
SET Email = REPLACE(MyTable.Email, SUBSTRING(MyTable.Email, CHARINDEX('@', MyTable.Email), LEN(MyTable.Email) - CHARINDEX(MyTable.Email, '@')), '@example.com')
WHERE MyTable.Email LIKE '%criteria%';
Written by William Luu
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Email
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#