各位好! 请问如何把一个表的数据更新啊?以下是我写的一小段程序,有错误,不知道怎么写。
update podetailtest set deliveryQty=(select tdeliveryqty  from  test)
where podetailtest.LineItemNo=test.LineItemno
and     podetailtest.refkey=test.refkey
and     podetailtest.PartNo_by=test.PartNo_by 这样错在那里啊?谢谢!

解决方案 »

  1.   

    update podetailtest set deliveryQty=tdeliveryqty  
    from TEST
     where podetailtest.LineItemNo=test.LineItemno
    and     podetailtest.refkey=test.refkey
    and     podetailtest.PartNo_by=test.PartNo_by
      

  2.   

    deliveryQty=(select tdeliveryqty  from  test)
    如果你的test表中有多条记录,会引起错误
    deliveryQty in (select tdeliveryqty  from  test)
    这样试试
      

  3.   

    update a set a.deliveryQty=b.tdeliveryqty  
    from podetailtest a,test b
    where a.LineItemNo=b.LineItemno
    and     a.refkey=b.refkey
    and     a.PartNo_by=b.PartNo_by
      

  4.   

    update podetailtest set deliveryQty=test.tdeliveryqty from podetailtest,test
    where podetailtest.LineItemNo=test.LineItemno
    and     podetailtest.refkey=test.refkey
    and     podetailtest.PartNo_by=test.PartNo_by 
      

  5.   

    update podetailtest set deliveryQty=(select tdeliveryqty  from  test
    where podetailtest.LineItemNo=test.LineItemno
    and     podetailtest.refkey=test.refkey
    and     podetailtest.PartNo_by=test.PartNo_by )
      

  6.   

    =(select tdeliveryqty  from  test)
    改成
    =(select top 1 tdeliveryqty  from  test)
    不知道行不行,还有就是如果这句没有符合条件的记录呢
      

  7.   

    试试这个:
    update podetailtest 
      set deliveryQty=t.tdeliveryqty 
    from podetailtest p inner join test t
    on   p.LineItemNo=t.LineItemno and p.refkey=t.refkey and p.PartNo_by=t.PartNo_by