请教 此bom表  @level产品层次 怎么展开运算的

mabuchi 2006-03-24 05:18:58
create procedure parts_explosion() //in @current char(25)

result(part_no char(25),structure_level integer,structure_qty decimal(15,6),children integer,siblings integer,open_children integer,same_level integer)

begin

declare @current char(25); //存放当前待查产品或零件

declare @level integer; //存放产品层次

declare @structure_qty decimal(15,4); //存放构成数量

select '最初产品编号' into @current; //后台测试用

create table #stack( //中间结果存表
current_item char(25) null,
part_level integer null,
part_qty decimal(15,4) null);

create table #parts( //最后返回结果存放表
part_no char(25) null,
structure_level integer null,
structure_qty decimal(15,6) null,
children integer null, //存放如果有子级产品.则1.否0.
siblings integer null, //存放是否邻居产品
open_children integer null, //前台用
same_level integer null, //前台用
);

/* SELECT @current='45860020A'*/

insert into #stack values(@current,1,1); //初始中间表

select 1 into @level;

while @level>0 loop

if exists(select* from #stack where part_level=@level) then

select current_item,part_qty into @current,

@structure_qty from #stack

where part_level=@level;

if @level<>1 then

insert into #parts values(@current,@level,@structure_qty,1,1,1,1)

end if

delete from #stack

where part_level=@level and current_item=@current;

insert into #stack

select part_no,@level+1,part_qty

from product_stru

where product_no=@current;

if @@rowcount>0 then

select @level+1 into @level;

if @@rowcount=1 then

update #parts set same_level=0

where part_no=@current

end if

else

update #parts set children=0

where part_no=@current

end if

else

select @level-1 into @level

end if

end loop
;

select part_no,structure_level,structure_qty,children,siblings,open_children,same_level from #parts

end


...全文
187 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mabuchi 2006-03-25
  • 打赏
  • 举报
回复
up
mabuchi 2006-03-25
  • 打赏
  • 举报
回复
只能看懂一部份  哪位能否说一下
mabuchi 2006-03-25
  • 打赏
  • 举报
回复
oracal 差不多
Yang_ 2006-03-25
  • 打赏
  • 举报
回复
这什么代码?
不是sql server的吧
mabuchi 2006-03-25
  • 打赏
  • 举报
回复
if @@rowcount>0 then

select @level+1 into @level;

if @@rowcount=1 then

update #parts set same_level=0

where part_no=@current

end if

else

update #parts set children=0

where part_no=@current

end if

else

select @level-1 into @level

end if
这里怎么理解

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧