2015-11-01 51 views
0

我有一个存储过程,如下所示,其中有一个循环运行。如果满足下面提到的条件,我需要返回循环并从循环阶段开始。我怎样才能做到这一点?如何在循环内部满足条件时跳回到存储过程内的循环增量阶段?

..... some steps......... 
while (@iv<= @rcnt) 
Begin 
CREATE TABLE #MathLogicTable 
(
IDNUM INTEGER IDENTITY(1,1), 
ATTRIBUTENAME VARCHAR(256), 
INPUTVALUES DECIMAL(15,3) 
) 

INSERT INTO #MathLogicTable 
     SELECT statements.................. 

if (not exists (select 1 from #MathLogicTable)) 
BEGIN 
set @[email protected]+1 (I need this step to go back to the start of the loop...if the condition satisfies) 
END 
------------------------------------------------------------ 
select............ 
update........ 
N Steps......... 
------------------------------------------------------------- 
End 

回答

0

你应该使用continue关键字:

if (not exists (select 1 from #MathLogicTable)) 
begin 
    set @[email protected]+1 
    continue 
end 
+0

真棒...感谢它得到了工作...... –