2014-10-07 51 views
0

我有工作就好以下select語句:informix的更新

select stock_master.stock_code, stk_stock_status, reorder_buyer, default_route_id, main_work_centre 
from stock_master, bill_of_materials_header, production_routing 
where stock_master.stock_code = bill_of_materials_header.stock_code 
    and bill_of_materials_header.default_route_id = production_routing.prh_route_id 
    and main_work_centre != "CNC"; 
    and stock_group >= 3201 and stock_group <= 3299; 

我想要做的就是更新stk_stock_status爲「M」這個條件,但不能似乎找出了更新命令的正確語法。任何指針都會非常有幫助。

回答

0

如果stk_stock_statusstock_master表中,並且此表有一些ID列,那麼將您的select轉換爲僅返回應該更新的標識符的select。它看起來像:

UPDATE stock_master SET stk_stock_status = 'M' WHERE stk_stock_id IN 
(
SELECT stk_stock_id 
FROM stock_master, bill_of_materials_header, production_routing 
WHERE stock_master.stock_code = bill_of_materials_header.stock_code 
    AND bill_of_materials_header.default_route_id = production_routing.prh_route_id 
    AND main_work_centre != 'CNC'; 
) 

PS請勿使用"刺激文字。 Informix允許使用它,但不能使用SQL標準。更好地使用'