2015-11-01 52 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

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