select * into #a from table1while exists (select * from #a) and exists ( select * from table2 where xm is null) begin update table2 set xm=t.xm,sex=t.sex from (select top 1 * from #a) as t,table2 where table2.bh=( select min(bh) frim table2 where xm is null) set rowcount 1 delete #a set rowcount 0 enddrop table #a
and exists ( select * from table2 where xm is null)
begin
update table2
set xm=t.xm,sex=t.sex
from (select top 1 * from #a) as t,table2
where table2.bh=(
select min(bh) frim table2 where xm is null)
set rowcount 1
delete #a
set rowcount 0
enddrop table #a