22,300
社区成员




declare @id int
set @id=12--设置插入值
update tb2 set c=(case when exists(select 1 from tb where a=@id) and exists(select 1 from tb2 where b=@id) then 0 when not exists(select 1 from tb where a=@id) and exists(select 1 from tb2 where b=@id) then 1 when exists(select 1 from tb where a=@id) and not exists(select 1 from tb2 where b=@id) then 2 end )
update tb2
set c = (case when exists (select 1 from tb1 where tb1.a = tb2.b) then 0 else 1 end)
from tb2
update tb2
set c = (case when exists (select 1 from tb1 where tb1.a = tb2.b) then 0 else 1 end)
from tb2
insert into tb2
select A,2
from(
select a from tb1 except select b from tb2
) t
update tb2
set c = (case when exists (select 1 from tb1 where tb1.a = tb2.b) then 0 else 1 end)
from tb2