http://expert.csdn.net/Expert/topic/2285/2285830.xml?temp=.1570551/*--树形数据处理方案 树形数据的排序,新增,修改,复制,删除,数据完整性检查,汇总统计
--邹建 2003.9--*/

解决方案 »

  1.   

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