诸位高人,大家好,小弟工作中遇到以下问题,在此求助,望大家不吝赐教。问题阐述如下:两个数据表tabA、tabB数据表 tabA            |     tabB字段名 numA   FLG      |     numB   FLG数据    1      a       |      10     a
       2      b       |      20     b
       3      c       |      
       4      d       | 请问如何将数据表tabA中符合tabA.FLG = tabB.FLG 的数据的numA字段,
更新为 tabA.numA + tabB.numB ?最终结果数据表 tabA            字段名 numA   FLG      数据    11      a       
       22      b       
       3      c             
       4      d

解决方案 »

  1.   

    update tabA
    set numA = tabA.numA   +   tabB.numB   
    from tabB
    where tabA.FLG   =   tabB.FLG   
      

  2.   

    try it ...update tabA a
       set a.numA = (
                     select a.numA+b.numB
                       from tabB b
                      where a.FLG = b.FLG 
                    )
     where exists (
                   select 1
                     from tabB b
                    where b.FLG = a.FLG
                  );
      

  3.   

    感谢 mantisXF 
    问题已经解决。
      

  4.   

    楼主问题解决了吗?我试着随便建了个数据库,建了两张表taba,tabb,然后按照mantisXF的方法在查询管理器里试了下,发现不行啊,老是报错,请问这是什么原因呢,求解。