有两个字符串,比较它们的不同部分。例如:
字符串1:"A-B-c;A-B-D;D-F-G;F-H-J"
字符串2:"A-B-c;A-B-D;D-F-G;F-H-J;Y-U-O;T-R-E"
两个字符串相比较,找出不同的部分,用存储过程该怎么做,例如上面的应该找出的字符串为"Y-U-O;T-R-E"

解决方案 »

  1.   

    select replace(字符串2, 字符串1, '')
      

  2.   


    +1patindex/charindex 也可以处理,LZ参考
      

  3.   

    http://topic.csdn.net/u/20101221/21/4d7b8a40-158d-477f-80ee-99a51c65b284.html参考13#的答案。
      

  4.   


    1楼的方法有个问题
    select replace('abcd','ab','')
    select replace('ab','abcd','')
    这两句的结果不一样
      

  5.   


    CREATE proc [dbo].[CompareString]
    @StringOne nvarchar(max),
    @StringTwo nvarchar(max)
        as
        if LEN(@StringOne)>=LEN(@StringTwo)
    begin
    select  substring(@StringOne,len(@StringTwo)+1,abs(len(@StringTwo)-len(@StringOne)))
    end
    else
    begin
        select  substring(@StringTwo,len(@StringOne)+1,abs(len(@StringOne)-len(@StringTwo)))
    end
    GO
      

  6.   

    CREATE proc [dbo].[CompareString]
    @StringOne nvarchar(max),
    @StringTwo nvarchar(max)
      as
      if LEN(@StringOne)>=LEN(@StringTwo)
    begin
    select replace((@StringOne,@StringTwo, '')
    end
    else
    begin
    select replace(@StringTwo,@StringOne, '')
    end
    GO
    两者结合起来就可以啦
      

  7.   


    exec CompareString 'A-B;A-C','D-F;A-C;F-G;A-B'
    得出的结果为“;F-G;A-B
      

  8.   


    select 
       *
    from
       a
    where
       not exists(select 1 from b where charindex(';'+a+';',';'+b+';)>0)
      

  9.   

    select 
       *
    from
       a
    where
       exists(select 1 from b where charindex(';'+a+';',';'+b+';')>0)