K
krisjim
Unregistered / Unconfirmed
GUEST, unregistred user!
请大家帮我看看为什么出现死循环???
注: bomidx 子结点 bomid 父结点 unitqty单机用量
PROCEDURE JH_P_ProductMaterial
create table tmp1(bomidx int,unitqty int)
DECLARE @bomidx INT
DECLARE @UnitQty INT
TRUNCATE TABLE TMP1
select bomidx,unitqty INTO #TMP1 from JH_BOM_Child where bomidx = 1
set identity_insert #tmp1 on
WHILE (exists (select * from #TMP1))
BEGIN
declare mycursor1 cursor for select bomidx, unitqty from #TMP1
open mycursor1
DELETE #TMP1 WHERE CURRENT OF mycursor1
fetch next from mycursor1 into @bomIdx, @UnitQty
while (@@fetch_status = 0)
begin
if not exists (select bomid from JH_BOM_Child where bomid = @bomIdx)
insert into tmp1 values(@bomIdx, @UnitQty)
else
INSERT #TMP1 SELECT bomidx,unitqty*@UnitQty FROM JH_BOM_Child WHERE bomid = @bomIDx
fetch next from mycursor1 into @bomIDx, @UnitQty
END
CLOSE mycursor1
DEALLOCATE mycursor1
END
select * from tmp1
注: bomidx 子结点 bomid 父结点 unitqty单机用量
PROCEDURE JH_P_ProductMaterial
create table tmp1(bomidx int,unitqty int)
DECLARE @bomidx INT
DECLARE @UnitQty INT
TRUNCATE TABLE TMP1
select bomidx,unitqty INTO #TMP1 from JH_BOM_Child where bomidx = 1
set identity_insert #tmp1 on
WHILE (exists (select * from #TMP1))
BEGIN
declare mycursor1 cursor for select bomidx, unitqty from #TMP1
open mycursor1
DELETE #TMP1 WHERE CURRENT OF mycursor1
fetch next from mycursor1 into @bomIdx, @UnitQty
while (@@fetch_status = 0)
begin
if not exists (select bomid from JH_BOM_Child where bomid = @bomIdx)
insert into tmp1 values(@bomIdx, @UnitQty)
else
INSERT #TMP1 SELECT bomidx,unitqty*@UnitQty FROM JH_BOM_Child WHERE bomid = @bomIDx
fetch next from mycursor1 into @bomIDx, @UnitQty
END
CLOSE mycursor1
DEALLOCATE mycursor1
END
select * from tmp1