Compare two tables and insert all records with added or removed status in 3rd table using SQL Server procedure

后端 未结 5 1535
梦谈多话
梦谈多话 2021-01-27 17:43

I have table A and table B . I have to compare this tables records and insert data to table C using SQL Server procedure in below format

table A

  name
          


        
5条回答
  •  盖世英雄少女心
    2021-01-27 18:11

    You could try using a some union and left join

    select  A.name, case when is null t1.name then 'newly addedd' end 
    from A 
    left  JOIN  (
      select  A.name from A 
      union B.name from B
    ) t1 
    
    union 
    select  B.name, case when is null t1.name then 'delete' end 
    from B
    left  JOIN  (
      select  A.name from A 
      union B.name from B
    ) t1 
    

提交回复
热议问题