update yh.orderhist a set fax=(select 'y' from yh.contact c,yh.orderdet d,yh.product p where a.orderid=o.orderid and c.contactid=o.contactid and d.orderid =o.orderid and d.prodid=p.prodid 
and o.branch is null) where a.ticket='0'

解决方案 »

  1.   

    楼上的写法是错的吧?这样不把部份记录设置成null了吗?update yh.orderhist oh
       set fax = 'y'
     where ticket = '0' 
       and exists
           (select o.orderid
              from yh.contact c
              , yh.orderhist o
              , yh.orderdet d
                , yh.product p
             where c.contactid = o.contactid 
               and d.orderid = o.orderid 
               and d.prodid = p.prodid 
               and o.orderid = oh.orderid
               and o.branch is null
           )
      

  2.   

    不清楚你的SQL是基于什么逻辑的,而且子查询会返回多少数据也不知道,试试这个update yh.orderhist oh
       set fax = 'y'
     where oh.rowid in
           (select o.rowid
              from yh.contact c
              , yh.orderdet d
                , yh.product p
                , yh.orderhist o
             where c.contactid = o.contactid 
               and d.orderid = o.orderid 
               and d.prodid = p.prodid 
               and o.branch is null
               and o.ticket = '0' 
           )