title: Sql Server print affected rows during while loop
body: <p>I have a stored procedure running on sql server 2008 looping over a table of ~50 million rows, deleting records one day at a time (approx. 25,000 records a day). I want to be able to watch this occur as the process runs via print statements to the messages window. I'd like to be able to see a message each time a day's worth of deletions is committed. Is there any way to do something like this? The procedure is roughly laid out like this:</p>
  
  <pre><code>WHILE EXISTS(&lt;query statement&gt;)
  BEGIN
  
  BEGIN TRAN
  
  DELETE
  FROM  &lt;table&gt;
  WHERE &lt;condition&gt;
  AND &lt;condition&gt;
  
  --need some sort of "rows affected" statement here
  
  COMMIT
  
  END
  </code></pre>