有两个
表1:
code  fname
1     sd
2     dc
3     df
表2:
code   fname
1      dv
2      dc
3      sd
4      re
以表2的code为准,比较表1中的数据,fname都相应改为表2的。就是执行后表1的数据为:
code      fname
1         dv
2         dc
3         sd
这个该怎么实现啊?

解决方案 »

  1.   

    update  t1
    set t1.fname=t2.fname
    from t1,t2
    where t1.code=t2.code
      

  2.   

    建议:update前最后先
    select t2.*
    from t1,t2
    where t1.code=t2.code
      

  3.   

    update  t1
    set t1.fname=t2.fname
    from t1 inner t2
    on t1.code=t2.codeselect * from t1
      

  4.   

    declare @t table(code int,fname varchar(10))
    insert into @t select 1,'sd'
    union all select 2,'dc'
    union all select 3,'df'declare @a table(code int,fname varchar(10))
    insert into @a select 1,'dv'
    union all select 2,'dc'
    union all select 3,'sd'
    union all select 4,'re'update a set a.fname=b.fname from @t a,@a b where a.code=b.code
    select * from @t
      

  5.   

    update from table1 a,table2 b
    set a.fname=b.fname
    where a.code=b.code