BOM展开的中间函数给大家

本文介绍了一个用于生产制造企业的BOM展开工作的存储过程函数。该函数通过递归方式展开物料清单(BOM),并记录每层物料的信息,如物料代码、数量及层级等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近一直在搞BOM展开的工作,其实在生产制造企业都是最需要的. 这里放BOM展开的中间函数,提供给需要展开BOM写存储的一些思路.
 
BOM展开存储过程中间函数,其他的存储过程展开都需要调用此存储过程函数
执行:Exec BOMCOMMONRpt @Code,@Sort,@ItemCode,@Quantity,@Level out
需要传入变量Code:需要展开的物料代码
                      Sort:排序
                      ItemCode:第一层的源物料
                      Quantity:父物料数量
                      Level :层级
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BOMCOMMONRpt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
Drop Procedure [dbo].[BOMCOMMONRpt]
GO

 

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

 

Create Procedure [dbo].[BOMCOMMONRpt]
(
       @ItemCode  nvarchar(40),
       @Sort     int,
       @Source nvarchar(50),
       @Quantity1 int,
       @Level   int   out
)
--With encryption
as

 

declare @LevCount int                     --LevelCount
declare @strSQL nvarchar(4000)       
declare @strSQL1 nvarchar(4000) 
declare @Father nvarchar(50)
declare @Code nvarchar(50)
declare @Quantity2 int

 

 

Set @strSQL = ''
Set @strSQL1 = ''
set @LevCount=@Level

 

Begin

 

--创建存储表
--    Create Table W_Temp1
--    (
--           IDNo int identity(1,1),                      --No
--           Father nvarchar(30)    ,                      --AcctCode
--           Code nvarchar(200)   ,                     --AcctName
--           Quantity int,
--           BOMLevel int,
--           SortID   int,
--           Source nvarchar(50),
--           BOMQnty int
--          
--    )

 

       --alter table W_Temp1 add BOMQnty int

 

       Declare @MyPrc Cursor
       Set @MyPrc = Cursor FOR
           Select  Father,Code,Quantity from itt1
           where Father =@ItemCode
      
       Open @MyPrc
       Fetch next from  @MyPrc Into @Father,@Code,@Quantity2
       While @@FETCH_STATUS = 0
       Begin

 

              --插入所有子件

 

              insert into W_Temp1 ( Father,Code,Quantity,BOMLevel,SortID,Source,BOMQnty) values (@Father,@Code,@Quantity2*@Quantity1,@LevCount,@Sort,@Source,@Quantity2)
                 
              Fetch next from  @MyPrc Into @Father,@Code,@Quantity2

 

       End
       Close @MyPrc
       Deallocate @MyPrc
 
       set @Level=@Level+1

 

 

End
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值