13、如果在mtl_system_items中,有不存在的物品ITEM时,要把其删除(或是把这些物品Item导入到系统中)
删除:delete cux_bill_temp b
where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2);
delete cux_bill_temp a
where not exists (select null from mtl_system_items where segment1=a.assembly_item and organization_id=2);
14、对没有物品Item的进行处理,把其放入另一临时表cux_item_temp中(以备查询及导入mtl_system_items表中)
delete cux_item_temp;
insert into cux_item_temp(
segment1,description)
select distinct item,item
from (
select distinct assembly_item item
from cux_bill_temp b
where not exists (select null from mtl_system_items where segment1=b.assembly_item and organization_id=2)
union
select distinct component_item item
from cux_bill_temp b
where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2)
)
;
将找到没有ITEM的BOM数据放到另一个表中,以备下次ITEM导入后在导BOM
create table cux_bom_temp1
select distinct item
from (
select distinct assembly_item item
from cux_bill_temp b
where not exists (select null from mtl_system_items where segment1=b.assembly_item and organization_id=2)
union
select distinct component_item item
from cux_bill_temp b
where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2)
)
15、从表mtl_system_items中把物品的编码ID加入中转表cux_bill_temp表(从项目主组织)中
update cux_bill_temp b
set assembly_item_id=(select inventory_item_id from mtl_system_items
where segment1=b.assembly_item and organization_id=2),
component_item_id=(select inventory_item_id from mtl_system_items
where segment1=b.component_item and organization_id=2);
