How to find diff between two string in SQL

前端 未结 4 837
自闭症患者
自闭症患者 2020-12-21 22:26

I have two strings, I want to get difference between contents of two strings in SQL ??

for example,

Declare @String1 as varchar(100)=\'a,b,c,d,e\';

         


        
4条回答
  •  遥遥无期
    2020-12-21 22:33

    First take the function from the following link Parse comma-separated string to make IN List of strings in the Where clause

    Then use the following query;

    Declare @String1 as varchar(100)='a,b,c,d,e';
    
    Declare @String2 as varchar(100)='b,e';
    
    SELECT
        s1.val
        ,s2.val
    FROM [dbo].[f_split](@String1,',') s1
    FULL OUTER JOIN [dbo].[f_split](@String2,',') s2
        ON s1.val = s2.val
    WHERE s1.val IS NULL
        OR s2.val IS NULL
    

    Which will give you the following results;

    val val
    a   NULL
    c   NULL
    d   NULL
    

提交回复
热议问题