declare @A table (R1 int,R2 int) insert into @A select 5,null union all select 7,null union all select 8,nulldeclare @B table (RB int) insert into @B select 4 union all select 9 union all select 13;with m1 as ( select row_number() over (order by (select 1)) as id, * from @A ), m2 as ( select row_number() over (order by (select 1)) as id, * from @B ), m3 as ( select R1,RB from m1 a,m2 b where a.id=b.id )--更新 update @A set R2=b.RB from @A a left join m3 b on a.R1=b.R1 --更新后的结果 select * from @A /* R1 R2 ----------- ----------- 5 4 7 9 8 13 */
declare @A table (R1 int,R2 int)
insert into @A
select 5,null union all
select 7,null union all
select 8,nulldeclare @B table (RB int)
insert into @B
select 4 union all
select 9 union all
select 13;with m1 as
(
select row_number() over (order by (select 1)) as id, * from @A
),
m2 as
(
select row_number() over (order by (select 1)) as id, * from @B
),
m3 as
(
select R1,RB from m1 a,m2 b where a.id=b.id
)--更新
update @A set R2=b.RB
from @A a left join m3 b on a.R1=b.R1
--更新后的结果
select * from @A
/*
R1 R2
----------- -----------
5 4
7 9
8 13
*/