小编Hsm*_*ith的帖子

SQL循环,如果BREAK

在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 …

sql-server control-structure

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

control-structure ×1

sql-server ×1