实际应用场景中,有需要对已经使用过的物料进行物料计量单位的修改,贴上修改语句:
--先查到需要参照更改的物料计量单位信息--
select
FItemid,--物料内码
FUnitGroupID,--计量单位组
FUnitID,--基本计量单位
FOrderUnitID,--采购计量单位
FSaleUnitID,--销售计量单位
FProductUnitID,--生产计量单位
FStoreUnitID--库存计量单位
from t_icitem where FNumber='test'
--以下语句是更新物料计量单位的--
update t_ICItem set
FUnitGroupID=1177,--计量单位组
FUnitID=1187,--基本计量单位
FOrderUnitID=1187,--采购计量单位
FSaleUnitID=1187,--销售计量单位
FProductUnitID=1187,--生产计量单位
FStoreUnitID=1187--库存计量单位
where FNumber='082-002777-00'--修改物料单位
--以下语句是更新历史单据的--
update ICStockBillEntry set FUnitID=1187 where FItemID=11416--修改出入库单据单位
update PORequestEntry set FUnitID=1187 where FItemID=11416--修改采购申请单单位
update POOrderEntry set FUnitID=1187 where FItemID=11416--修改采购订单单位
update POInStockEntry set FUnitID=1187 where FItemID=11416--修改收料送检单单位
update t_SupplyEntry SET FUnitID=1187 where FItemID=11416--修改采购价格管理数据单位
最后刷新一下BOM引用的计量单位:
先看下有没有不一致的数据:
--BOM父项
select t.FBOMNumber,t.FUnitID,t1.FUnitID from ICBOM t
inner join t_ICItem t1 on t1.FItemID=t.FItemID
where t.FUnitID<>t1.FUnitID
--BOM子项
select t.FUnitID,t1.FUnitID from ICBOMChild t
inner join t_ICItem t1 on t1.FItemID=t.FItemID
where t.FUnitID<>t1.FUnitID
如果有不一致的,调整语句如下:
--更新父项计量单位
update a set a.FUnitID=b.FUnitID
from ICBOM a,t_ICItem b where a.FItemID=b.FItemID AND a.FUnitID<>b.FUnitID
--更新子项计量单位
update a set a.FUnitID=b.FUnitID
from ICBOMChild a,t_ICItem b where a.FItemID=b.FItemID AND a.FUnitID<>b.FUnitID