0

对,我有一些 21000 条记录,其中电子邮件地址末尾有数字(. + 15 位长数字,例如:xyz@gmail.com.201211200200027)

现在,我能想到的最佳解决方案是:

Update TABLE
set EmailAddress = (
select substring (EmailAddress, 1, (len(EmailAddress) - 16))
from TABLE)
Where ISNUMERIC(RIGHT(Emailaddress, 15)) = 1

上面的代码不起作用(我不是 T-SQL 专家,如果这段代码看起来很愚蠢,请原谅我

如果我告诉该代码一个特定的电子邮件地址,那么它就可以工作。像这样的东西:

Update TABLE
set EmailAddress = (
select substring (EmailAddress, 1, (len(EmailAddress) - 16))
from TABLE)
Where ISNUMERIC(RIGHT(Emailaddress, 15)) = 1
and Emailaddress is 'xyz@gmail.com.201211200200027'

那么,如何更新这些电子邮件地址并删除最后 16 个字符?

4

1 回答 1

0

尝试这个;

UPDATE yourTable
SET EmailAddress = LEFT(EmailAddress, LEN(EmailAddress) - 16 )
WHERE PATINDEX('%[^0-9]%', RIGHT(EmailAddress, 15)) = 0 AND LEN(EmailAddress) > 16
于 2013-01-29T11:11:29.310 回答