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 begin11 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 end16 return @result17 end18 GO19 --('塗聚文','塗','塗聚文','1','23','1')20 21 --測試22 select dbo.StringRemove('塗聚文,塗,塗聚文,1,23,1')