Sql:去除字符串中的相同的字符串函數 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

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

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

    2 create function StringRemove(@str nvarchar(2000))

    3 returns varchar(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')

    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构(分析)整合学习, 情商(EQ)运筹(学)成功.---Geovin Du(涂聚文)

最新文章