求一个SQL(A表(id,qty),b表(id,qty)),要求:如A表中(ID)=B表中(ID),把B表中的(QTY)更新A表中的(QTU)

解决方案 »

  1.   

    update A set [qty]=(select qty from B where A.id=B.id)
      

  2.   

    应该为:update A set [qty]=isnull((select qty from B where A.id=B.id),name)刚刚少考虑了一种情况,当A表中的ID 在B表不存在的时候,会把A表中的qty的值置为NULL;
      

  3.   

    update B
    set QTY=(select QTY from A where ID=B.ID)
    from B
      

  4.   

    对不起,表的顺序弄反了,修改如下:update A
    set QTY=(select QTY from B where ID=A.ID)
    from A
      

  5.   

    update A set qty = (select qty from B where B.Id = A.Id)