title: is "select count(*) from..." more reliable than @@ROWCOUNT?
body: <p>I have a proc that inserts records to a temp table. In pseudocode it looks like this: </p>
  
  <pre><code>Create temp table 
  a. Insert rows into temp table based on stringent criteria
  b. if no rows were inserted, insert based on less stringent criteria 
  c. if there are still no rows, try again with even less stringent criteria
  select from temp table
  </code></pre>
  
  <p>There are a lot of <code>IF @@rowcount = 0</code> checks in the code to see if the table has any rows. The issue is that the proc isn't really doing what it looks like it should be doing and it's inserting the same row twice (steps a and c are being executed). However, if I change it to check this way <code>IF ( (select count(*) from     @temp) = 0)</code> the proc works exactly as expected. </p>
  
  <p>Which makes me think that <code>@@rowcount</code> isn't the best solution to this problem. But I'm adding in extra work via the <code>SELECT COUNT(*)</code>. Which is the better solution? </p>