隐藏

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

发布:2020/7/28 17:37:32作者:管理员 来源:本站 浏览次数:820

---去除字符串中重復的值函數

create function StringRemove(@str nvarchar(2000))

  returns nvarchar(2000)
  as
  begin
      declare @result nvarchar(2000),@temp nvarchar(1000)
      set @result=''
      set @temp=''
      while(charindex(',',@str)<>0)
         begin
             set @temp=substring(@str,1,charindex(',',@str))   
             if(charindex(@temp,@result)<=0)           
                 set @result=@result+@temp       
             set @str=stuff(@str,1,charindex(',',@str),'')
         end
     return @result
end
 GO