您的位置:首页 > 其它

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

2008-05-01 03:11 246 查看
一: 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 *******/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: