有A,B两表:
A                  B
R1  R2             RB
1   null           4
2   null           5
3   null           6
update 表A 得R2列实现效果
A
R1  R2
1   4
2   5
3   6

解决方案 »

  1.   


    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
    */