update B
set B.div = (case
when B.id in (select distinct id from A) then (select div from A where id = B.id)
else (select div from A where id='00') end
)
from A,B
where B.div is null
先运行
update B set div = a. a2
from
(
select ID as a1
,DIV as a2
from A
) as a
where div is null
and ID = a.a1
再运行
update B set div = a. a2
from
(
select ID as a1
,DIV as a2
from A
where ID = 00
) as a
where div is null
update b
set b.div = (case
when b.id in (select distinct div from a) then a.div
when b.id not in (select distinct div from a) then '00'
)
from a,b
where b.div is null