我的表email
中有一列person
,电子邮件列中包含
sam@yahoo.com
xxxashish@gmail.com
sunny@rediff.com
xxxSomil@google.com
现在,我想要更新电子邮件列的值,并从电子邮件ID的开头删除所有xxx
。任何想法如何实现这一目标?
示例:xxxashish@gmail.com
应为ashish@gmail.com
答案 0 :(得分:6)
试
UPDATE person
SET email = RIGHT(email, LEN(email) - 3)
WHERE email LIKE 'xxx%';
这样你就不会取代文本中可能出现的xxx
因此xxxladidaxxx@gmail.com
将返回ladidaxxx@gmail.com
答案 1 :(得分:4)
试
update
person
set email = REPLACE(email,'xxx','')
where email like 'xxx%'
如果xxx介于电子邮件之间,上面的内容也将替换它。对于以下代码,
update
person
set email = RIGHT(email, LEN(email) - 3)
where email like 'xxx%'
答案 2 :(得分:0)
您也可以查看。
Declare @t table(email varchar(50))
insert into @t values ('sam@yahoo.com'), ('xxxashish@gmail.com' ),('sunny@rediff.com' ),('xxxSomil@google.com')
UPDATE @t
SET email = STUFF( email , 1 , 3 ,'')
WHERE email LIKE 'xxx%'
select * from @t
How to remove the first character if it is a specific character in SQL