title: How to check if anything was inserted with INSERT SELECT (T-SQL)
body: <p>I have an insert statement:</p>
  
  <pre><code>insert into parentTbl
  select firstId, secondId, thirdId, dateTm
  from importTbl
  where codeId = @codeIdParam
  </code></pre>
  
  <p>I need to reliably find out if that insert inserted anything at all.  Ideally, I would like to set a <code>@insertedCount</code> variable to the number of rows inserted, even if that is 0.</p>
  
  <p>I am currently using:</p>
  
  <pre><code>set @insertedCount = @@ROWCOUNT
  </code></pre>
  
  <p>But that only seems to get the last number of inserted rows - the problem is that if the <code>INSERT SELECT</code> statement did not insert anything the <code>@@ROWCOUNT</code> does not return 0.</p>