两个表结构如下
tb1
ID   B   C    D    E   F...
1 null null null null  X
3 null null null null  X
5 null null null null  X
...
tb2
ID B  C  D  E 
1  X  X  X  X
2  X  X  X  X
3  X  X  X  X
....
X表示有数据
null表示没数据
我想把tb2里有数据的字段导入到tb1,请教该如何写?

解决方案 »

  1.   

    Update x set x.b=y.b, x.c=y.c, x.d=y.d, x.e=y.e
    from tb1 as x inner join tb2 as y on x.id=y.id
      

  2.   

    Update tb1 set tb1.b=tb2.b, tb1.c=tb2.c, tb1.d=tb2.d, tb1.e=tb2.e
    from tb1,tb2
    where tb1.id=tb2.id and (tb1.b is null and tb1.c is null and tb1.d is null)
      

  3.   

    Update tb1 set b=isnull(tb2.b,tb1.b), c=isnull(tb2.c,tb1,c),
     d=isnull(tb2.d,tb1.d), e=isnull(tb2.e,tb1.e)
    from tb2
    where tb2.id = tb1.id
      

  4.   

    insert into Tb1(ID,b,c,d) select * from tb2
      

  5.   

    按楼上说的,那怎么写 SQL语句,得写存储过程了吧