我的代码如下所示:
WHILE @@FETCH_STATUS = 0
BEGIN
IF (@Result = 'S')
-- A lot of code
FETCH NEXT FROM CUR INTO @A
END
CLOSE CUR;
DEALLOCATE CUR;
我意识到我可以使用BEGIN END和ELSE并输入"很多代码"在那里,但有另一种方法,我可以做另一个FETCH并跳到WHILE的结尾?
答案 0 :(得分:1)
BREAK
and CONTINUE
statements。
你可以说:
WHILE @@FETCH_STATUS = 0
BEGIN
IF (@Result <> 'S')
BEGIN
FETCH NEXT FROM CUR INTO @A;
CONTINUE;
END
-- A lot of code
FETCH NEXT FROM CUR INTO @A
END
CLOSE CUR;
DEALLOCATE CUR;