A表:
    Acol1       Acol2
     1           null
     2           null
     3           null
     1           null
B表:
    Bcol1       Bclo2
     1            a
     2            b 
     3            c
要得到结果:
 A表:     
    Acol1       Acol2
     1            a
     2            b
     3            c
     1            a怎么写update ?

解决方案 »

  1.   

    update a set a.acol2=b.bcol2 from a,b where a.acol1=b.bcol1
      

  2.   

    update a set a.Acol2=b.Bcol2
    from a inner join b on a.Acol1=b.Bcol1
      

  3.   

    create table A (Acol1 int,Acol2 char(2))
    insert into a
    select 1,null
    union all
    select 2,null
    union all
    select 3,null
    union all
    select 1,nullcreate table b (Bcol1 int,Bcol2 char(2))
    insert into b
    select 1,'a'
    union all
    select 2,'b'
    union all
    select 3,'c'UPDATE a SET A.ACOL2=B.BCOl2
    FROM A,B
    WHERE A.ACOL1=B.BCOL1select * from a
      

  4.   

    update a set a.Acol2=b.Bclo2 where a.Acol1=b.Bcol1
      

  5.   

    各位都错了,应该为:
    update A set Acol2 = ( select Bcol2 from B where A.Acol1 = B.Bcol1 )
      

  6.   


    declare @t table(acol1 int ,acol2 varchar(2))
    declare @t1 table(bcol1 int ,bcol2 varchar(2))insert into @t
    select     1,           null union all
    select     2,           null union all
    select     3,           null union all
    select     1,           nullinsert into @t1
    select     1,            'a' union
    select     2,            'b' union
    select     3,            'c' update @t 
    set acol2 = b.bcol2
    from @t a , @t1 b
    where a.acol1 = b.bcol1
      

  7.   

    --
    update A set Acol2=B.Bcol2 from A,B where A.Acol1=B.col1