ERP系统中与BOM有关的常用方法

一: BOM展开(按任一父结点展开到最底层)
以下写一个简单的,视具体要求稍做修改即可。
create table 表(levelid int,levelname char(2),parent int)
insert 表 select  1,        'AA'     ,    0
union all select  2 ,       'BB'    ,     1
union all select  3  ,      'CC'   ,      1
union all select  4   ,     'DD'  ,       2
union all select  5    ,    'EE' ,        3
union all select  6     ,   'FF',         5

create function bom (@name char(2))
returns @tb table (levelid int,levelname char(2),parent int)
as
begin
insert @tb select levelID,LevelName,parent from 表 where Levelname = @name
while @@rowcount > 0
 insert @tb select levelID,LevelName,parent from 表
  where parent in (select levelID from @tb)
  and levelID not in (select levelID from @tb)
return
end

select * from dbo.bom('bb')
levelid     levelname parent     
----------- --------- -----------
2           BB        1
4           DD        2

(所影响的行数为 2 行)

 

二: LLC(最低层码) 
1:物料主文件中至少有这两个字段
itemNo,llc
2:BOM中至少有这两个字段 (树状)
parentItem,itemNo
3:
Create  Procedure LLC
As
Update 物料主文件 set llc = 0  --先将LLC全部清为0
Declare @i tinyint
Set @i = 0
While @i <= 10  -- 假设BOM最多只有10层
Begin
 Update a Set a.llc = @i + 1    --子结点的LLC加1
  From 物料主文件 a
  Join bom b on a.itemNo = b.itemNo
  Join 物料主文件 c on c.itemNo = b.parentItem
  where c.llc = @i
 Set @i = @i + 1
End

/*********** Usage:   Exec LLC             *******/

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值