ERP系統中與BOM有關的常用方法(轉)

urinator發表於2007-08-04
ERP系統中與BOM有關的常用方法 http://www.226e.net/article/13/Article6908_1.htm
一: 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 *******/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7942439/viewspace-20156/,如需轉載,請註明出處,否則將追究法律責任。

相關文章