龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Sql Server开发 >

sqlserver中去除字符串中连续的分隔符的sql语句

时间:2014-06-01 02:00来源:网络整理 作者:网络 点击:
分享到:
sqlserver中去除字符串中连续的分隔符的sql语句,需要的朋友可以参考下
以下测试用于去除任何字符串中连线的分隔符
代码如下:

--去除字符串中连续的分隔符
declare @str nvarchar(200)
declare @split nvarchar(200),@times int
set @str='中 国1 2 34 55 5 6 7 7';--字符
set @split=' '; --分隔符
select @times=(len(@str)-len(replace(@str,@split+@split,'')))/2
while @times>0
begin
set @str=REPLACE(@str,@split+@split,' ')
set @times=@times-1
end
select @str

希望对大家有作用

测试结果:

中 国1 2 34 55 5 6 7 7

(1 行受影响)
精彩图集

赞助商链接