DECLARE @yl decimal(18,6),@path nvarchar(800),@cd int,@cec int
DECLARE boms CURSOR
FOR SELECT sl, path ,len(path),ceci FROM bomt where scbs='P' and ceci>0 -----获取是生产件的数据,根据层数逐阶展开
--DECLARE @count smallint
--SELECT @count = 1
OPEN boms
FETCH NEXT FROM boms INTO @yl,@path,@cd,@cec
WHILE (@@fetch_status <> -1)
BEGIN
-------------更新用量
UPDATE bomt
SET sl=@yl*sl
WHERE ceci=@cec+1 ------制定下一层,即限制它的第一阶子件,而不往下阶延伸
and left(path,@cd)=@path
FETCH NEXT FROM boms INTO @yl,@path,@cd,@cec
END
CLOSE boms
DEALLOCATE boms
--------显示
select ceci as 层次,parent_item as 物料, itemname as 物料名称, @bz*sl as 标准设计数量, dw as 单位, ck as 仓库, fhf as 发货方法,scbs as BOM类型 from bomt order by path
end
GO
DECLARE boms CURSOR
FOR SELECT sl, path ,len(path),ceci FROM bomt where scbs='P' and ceci>0 -----获取是生产件的数据,根据层数逐阶展开
--DECLARE @count smallint
--SELECT @count = 1
OPEN boms
FETCH NEXT FROM boms INTO @yl,@path,@cd,@cec
WHILE (@@fetch_status <> -1)
BEGIN
-------------更新用量
UPDATE bomt
SET sl=@yl*sl
WHERE ceci=@cec+1 ------制定下一层,即限制它的第一阶子件,而不往下阶延伸
and left(path,@cd)=@path
FETCH NEXT FROM boms INTO @yl,@path,@cd,@cec
END
CLOSE boms
DEALLOCATE boms
--------显示
select ceci as 层次,parent_item as 物料, itemname as 物料名称, @bz*sl as 标准设计数量, dw as 单位, ck as 仓库, fhf as 发货方法,scbs as BOM类型 from bomt order by path
end
GO