我在 SPROC 中有插入语句(简化),如下所示
SET ROWCOUNT 100
WHILE(1=1)
BEGIN
INSERT INTO table1
SELECT *
FROM table2
WHERE some_condition
-- EDIT: Realized forgot to include this following vital line that is causing issue
SET @var = @var + @@ROWCOUNT
-- @@ROWCOUNT now takes on a value of 1, which will cause the following IF check to fail even when no lines are inserted
IF(@@ROWCOUNT = 0)
BEGIN
BREAK
END
END
但问题是,在任何操作之后,即使没有更多行适合 my some_condition
,@@ROWCOUNT
也等于1
,而不是0
。
当返回 0 行与我的匹配时,如何打破该循环some_condition
?