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

后端 未结 8 892
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 07:46

I\'ve come across a interesting scenario (at least for me) in a stored procedure. Would like to have experts opinion and thoughts on it.

DECLARE @loopcounter         


        
8条回答
  •  被撕碎了的回忆
    2020-12-24 08:09

    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 :-)

提交回复
热议问题