适用环境:
人工的去展开BOM
CREATE function f_pcode1(@code varchar(20))
returns @re1 table(code varchar(20),father varchar(20),uom varchar(5),quantity float,level1 int)
as
begin
declare @l int
declare @father varchar(20)
declare @uom varchar(5)
declare @quantity float
set @l=0
insert @re1 select @code,@father,@uom,@quantity,@l
while @@rowcount>0
begin
  set @l=@l+1
  insert @re1(code,father,uom,quantity,level1) select a.code,a.father,a.uom,a.quantity,@l
  from itt1 a,@re1 b
  where a.father=b.code collate database_default
   and b.level1=@l-1
end
return
end


用这个SQL我实现了这样一种功能:按销售订单查询成品的标准BOM清单,并计算需求。
输入成品的料号
输出父料号、子料号、单位、用量、BOM级别


关于B1的两个功能(二)按销售订单展开生产订单的用料清单

简单的说:就是输出一个销售订单销售物料的生产订单用料清单
CREATE function f_wo(@code_a varchar(20),@code_b varchar(20))
returns @re1 table(DocEntry int,code varchar(20),father varchar(20),uom varchar(5), PlannedQty float,IssuedQty float,level1 int)
as
begin
declare @l int
DECLARE @DocEntry INT
declare @father varchar(20)
declare @code varchar(20)
declare @IssuedQty float
declare @PlannedQty float
declare @re2 TABLE (DocEntry int,code varchar(20),father varchar(20), PlannedQty float,IssuedQty float,OriginNum int)

insert @re2(DocEntry,code,father,PlannedQty,IssuedQty,OriginNum) SELECT DiSTinct T1.DocEntry,T1.ItemCode, T0.ItemCode,T1.PlannedQty, T1.IssuedQty ,T0.OriginNum from OWOR T0 INNER JOIN WOR1 T1 ON T0.DocEntry = T1.DocEntry where   t0.OriginNum = @code_a

set @l=0
insert @re1(code,father,PlannedQty,IssuedQty,level1) select @code_b,@father,@PlannedQty,@IssuedQty,@l
while @@rowcount>0
begin
set @l=@l+1
insert @re1(DocEntry,code,father,IssuedQty,PlannedQty,level1) select DiSTinct a.DocEntry,a.code,a.father,a.IssuedQty,a.PlannedQty,@l
from @re2 a,@re1 b
where a.father=b.code collate database_default
and b.level1=@l-1
end
return
end
--------------
这个就是按单生产的SQL。
输入项目:销售订单号、销售订单销售的成品料号。
输出:
生产订单号
料号
父料号
发出数量
计划数量
BOM级别


由以上的两个功能可以开发出:按销售订单生产、计划的功能。
posted on 2007-12-14 23:49  沧海-重庆  阅读(3732)  评论(0编辑  收藏  举报