有现成的,稍改一下应该就可以了。 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 *******/
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 *******/