您可以创建CLR存储过程来执行正则表达式替换.这是一篇关于该主题的文章:http:
//weblogs.sqlteam.com/jeffs/archive/2007/04/27/SQL-2005-Regular-Expression-Replace.aspx
然后你可以做这样的事情:
UPDATE your_table
SET col1 = dbo.RegExReplace(col1, '[^A-Za-z]','');
Run Code Online (Sandbox Code Playgroud)
编辑:既然CLR不是一个选项,看看这个链接,那里有一个dbo.RegexReplace用t-sql编写的函数,而不是CLR.您可以通过以下方式使用该功能:
首先,你需要运行它来启用Ole:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Run Code Online (Sandbox Code Playgroud)
然后创建dbo.RegexReplace我提供的链接中给出的功能.
然后你可以这样做:
create table your_table(col1 varchar(500))
go
insert into your_table values ('aBCCa1234!!fAkk9943');
update your_table set col1 = dbo.RegexReplace('[^A-Za-z]','',col1,1,1);
select * from your_table
Result:
aBCCafAkk
Run Code Online (Sandbox Code Playgroud)