sqlserver中去除字符串中連續(xù)的分隔符的sql語句
更新時間:2012年05月27日 22:52:56 作者:
sqlserver中去除字符串中連續(xù)的分隔符的sql語句,需要的朋友可以參考下
以下測試用于去除任何字符串中連線的分隔符
--去除字符串中連續(xù)的分隔符
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
希望對大家有作用
測試結(jié)果:
中 國1 2 34 55 5 6 7 7
(1 行受影響)
復(fù)制代碼 代碼如下:
--去除字符串中連續(xù)的分隔符
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
希望對大家有作用
測試結(jié)果:
中 國1 2 34 55 5 6 7 7
(1 行受影響)
相關(guān)文章
mssql和sqlite中關(guān)于if not exists 的寫法
本文介紹下sql server查詢中,有關(guān)if exists與if not exists關(guān)鍵字的用法,有需要的朋友參考下2014-04-04SQL Server中實(shí)現(xiàn)二進(jìn)制與字符類型之間的數(shù)據(jù)轉(zhuǎn)換
在SQL Server 數(shù)據(jù)庫中,如何實(shí)現(xiàn)二進(jìn)制數(shù)據(jù)與字符串?dāng)?shù)據(jù)之間的直接轉(zhuǎn)換2012-11-11輕量級數(shù)據(jù)庫SQL?Server?Express?LocalDb介紹
這篇文章介紹了輕量級數(shù)據(jù)庫SQL?Server?Express?LocalDb,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06