informix根据另一个表中的值进行更新

时间:2014-10-07 07:16:23

标签: informix

我有以下select语句可以正常工作:

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更新为&#34; M&#34;对于这种情况,但似乎无法找出更新命令的正确语法。任何指针都会非常有用。

1 个答案:

答案 0 :(得分: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标准允许的。更好地使用'

相关问题