title: How to use @@ROWCOUNT in IF statement as well as within BEGIN..END block?
body: <p>My code is as follows: </p>
  
  <pre><code>SET @var = (SELECT var FROM dbo.varDB WHERE varName = @varName)
  
  IF (@@ROWCOUNT &gt; 0)
      BEGIN
          //carry out insert
      END
  </code></pre>
  
  <p>Am I right in saying this will always return a <em>1</em> for <em>@@ROWCOUNT</em> as it carries out an assignment last? </p>
  
  <p>If so, what would be the most elegant solution to allow me to:</p>
  
  <ul>
  <li>Create variable with the result from my query stored in it</li>
  <li>Test if the query returns any results</li>
  </ul>