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
You can do this with a full join
and conditional logic:
select
coalesce(a.name, b.name) name,
case
when a.name is null then 'newly added'
when b.name is null then 'removed'
end status
from tablea a
full join tableb b on b.name = a.name
order by name
Demo on DB Fiddle:
name | status :--- | :---------- A | null B | null C | null D | null E | removed F | null G | null Q | newly added