Variables scope which are defined within a while block in stored procedures – SQl Server

The variable scope is the whole batch in this case a stored procedure.

It isn’t re-declared every loop

So this is exactly as expected

Edit:

There is a recent blog article which is quite similar. The author was quickly corrected 🙂

Leave a Comment