Tomislav Mladenovski
Tomislav Mladenovski

Reputation: 35

SQL Insert/update field with text before a character

I am using MySQL and one of my tables, User_tb, has a column, user_email, where I store users' email addresses. I am relatively new to SQL, but I need to insert 'Sponsored' before the @ from the email address.

Example, [email protected] => [email protected]

All my research points me to using substr however I am not exactly sure how to actually executed on it. Any help is appreciated.

Upvotes: 1

Views: 855

Answers (2)

Aaron Burrows
Aaron Burrows

Reputation: 1

welcome.

You can do the following:

UPDATE MyTable

SET emailColumn = REPLACE (emailColumn, '@', 'Sponsored@')

This way you replace any @ symbol with the additional characters that you need. You can test this with the following:

SELECT REPLACE (emailcolumn, '@', 'Sponsored@') as emailColumn From MyTable

Upvotes: 0

Daniel A. Thompson
Daniel A. Thompson

Reputation: 1924

update User_tb set user_email = replace(user_email, '@', 'Sponsored@')

http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace

Upvotes: 2

Related Questions