title: TSQL break loop when @@ROWCOUNT = 0
body: <p>I have insert statements (simplified) in a SPROC like the following</p>
  
  <pre><code>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
  </code></pre>
  
  <p>But the issue is, after any operation even when no more rows fit my <code>some_condition</code>, <code>@@ROWCOUNT</code> is equal to <code>1</code>, not <code>0</code>.</p>
  
  <p>How can I break that loop when there are 0 rows returned matching my <code>some_condition</code>?</p>