下面有一些代码返回一个干净的字符串
如何在输出中保留逗号
select @cleanline=line from #tbl
While PatIndex('%[^A-Z,a-z,0-9]%', @cleanline) > 0
Set @cleanline = Stuff(@cleanline, PatIndex('%[^A-Z,a-z,0-9]%', @cleanline), 1, '')
print @cleanline
由于 罗布
答案 0 :(得分:3)
将 %[^A-Z,a-z,0-9]%
更改为%[^A-Z0-9]%
或%[^A-Za-z0-9]%
默认情况下,SQL Server不区分大小写,您不需要pattern-match strings中的逗号
编辑:结果是数据中有没有逗号...
select @cleanline = line from #tbl
set @tokeeppattern = '%[^A-Z,a-z0-9' + CHAR(9) + ']%'
While PatIndex(@tokeeppattern, @cleanline) > 0
Set @cleanline = Stuff(@cleanline, PatIndex(@tokeeppattern, @cleanline), 1, '')
print @cleanline