ARAPClearItems这个分录表里,在RPBillID='00000000000000005191'的条件下CustomField6一共有13行需要批量更新,select里的语句查出来确实也是13行,但是为什么还是提示单行子查询返回多个行,求大神指点。
update ARAPClearItems  set CustomField6 = (select (a.TransAuditValue/b.TaxInValue)*(nvl(a.CustomField5,0))
 from ARAPClearItems a ,SalesInvoiceItems b 
 where a.ARAPbillID=b.SalesInvoiceid
  and a.billitemid=b.SalesInvoiceItemid
  and a.invsign='1'
  and a.ARAPsourcetypecode='0003'
  and b.TaxInValue<>0
  and a.TransAuditValue<>0)
   where RPBillID='00000000000000005191'

解决方案 »

  1.   

    子查询里面加上RPBillID限制。
    update ARAPClearItems c  set CustomField6 = (select (a.TransAuditValue/b.TaxInValue)*(nvl(a.CustomField5,0))
     from ARAPClearItems a ,SalesInvoiceItems b 
     where a.ARAPbillID=b.SalesInvoiceid
      and a.billitemid=b.SalesInvoiceItemid
      and a.RPBillID = c.RPBillID
      and a.invsign='1'
      and a.ARAPsourcetypecode='0003'
      and b.TaxInValue<>0
      and a.TransAuditValue<>0)
       where RPBillID='00000000000000005191'
      

  2.   

    更新数据不是一一对应的吗?update 表 set 字段 = 某一个值, 不是楼主想的一行一行更新。是整体更新
      

  3.   


    -- ARAPClearItems  写一次就可了,你重复了。
    update ARAPClearItems  a set CustomField6 = (select (a.TransAuditValue/b.TaxInValue)*(nvl(a.CustomField5,0))
     from SalesInvoiceItems b 
     where a.ARAPbillID=b.SalesInvoiceid
      and a.billitemid=b.SalesInvoiceItemid
      and a.invsign='1'
      and a.ARAPsourcetypecode='0003'
      and b.TaxInValue<>0
      and a.TransAuditValue<>0)
       where RPBillID='00000000000000005191'
    and exists() -- 这里最好再写一个遍刚才的子查询。