Sql: 去除字符串中的相同的字符串函數

 1 ---去除字符串中重復的值函數
 2 create function StringRemove(@str nvarchar(2000))
 3 returns nvarchar(2000)
 4 as
 5 begin
 6     declare @result nvarchar(2000),@temp nvarchar(1000)
 7     set @result=''
 8     set @temp=''
 9     while(charindex(',',@str)<>0)
10         begin
11             set @temp=substring(@str,1,charindex(',',@str))   
12             if(charindex(@temp,@result)<=0)           
13                 set @result=@result+@temp       
14             set @str=stuff(@str,1,charindex(',',@str),'')
15         end
16     return @result
17 end
18 GO
19 --('塗聚文','塗','塗聚文','1','23','1')
20 
21 --測試
22 select dbo.StringRemove('塗聚文,塗,塗聚文,1,23,1')

 

posted @ 2013-01-19 17:17  ®Geovin Du Dream Park™  阅读(460)  评论(0编辑  收藏  举报