I have created a little complex stored procedure on SQL Server 2008 R2 and this SP also contains some user defined functions. Those UDFs and the SP itself has some while loops inside them.
I would like determine how many times something has been looped when I call this SP.
Any change I can do this?
SQL Profiler doesn’t have any way to do this, as far as I know. What I’d do is create a temporary table (provided you are only interested in the number of iterations for a single connection) to increment the single count variable, and then you can output the value that is stored in that temp table at the end of the loop.
Something like:
I made an
idfield in case there is more than one “counter” you may want.