在SQL Server 2012存储过程中,我有几个嵌套结构.我想打破它们的单层.
我认为msdn https://msdn.microsoft.com/en-CA/library/ms181271.aspx中对BREAK的描述就在我身边.但是我在通过调试单步执行时会遇到一些奇怪的行为.我说奇怪,因为它不一致.有时它会逃到我期望的层......有时它会跳过一对.
WHILE ... BEGIN
stuff1
IF...BEGIN
stuff2
WHILE ... BEGIN
stuff3
IF .... BEGIN
stuff4
IF @NumberRecords=0 BREAK
stuff5
END
--stuff6
if @NumberRecords=0 and @loopBOMRowCount=@ResultsSOloopstart-1 break
--on the last occasion I observed, @loopBOMRowCount was 6 and @ResultsSOloopstart 71 and it never highlighted this section, either way
SET @loopBOMRowCount = @loopBOMRowCount + 1
END
stuff7 --nothing actually here
END
--stuff8
SET @periodloopcount=@periodloopcount+1
--this is where it ended up highlighting on that last occasion
END
stuff9
Run Code Online (Sandbox Code Playgroud)
所以如果NumberRecords …