title: Why is SQL rowcount not returning in my stored procedure output parameter?
body: <p>I have a stored procedure with pseudocode like this:</p>
  
  <pre><code>ALTER PROCEDURE myProcedure(@param1 int, @param2 int, @returnCode int output)
  AS 
  BEGIN
     SELECT .... -- my query here
  
     SET @returnCode = @@ROWCOUNT
  END
  </code></pre>
  
  <p>However, when I execute this stored procedure, @returnCode is NULL:</p>
  
  <pre><code>DECLARE @returnCode INT
  EXEC myProcedure 1, 1, @returnCode
  SELECT @returnCode
  </code></pre>
  
  <p>Returns NULL.</p>
  
  <p>However, if I just do a select within the proc rather than setting the return code - <code>SELECT @@ROWCOUNT</code> - I get the correct row count. </p>
  
  <p>How can I return this row count in the output param?</p>