Variables scope which are defined within a while block in stored procedures - SQl Server
问题 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 INT SET @loopcounter=10 WHILE @loopcounter > 0 BEGIN DECLARE @insidevalue int IF (@loopcounter%2 = 0) SET @insidevalue = @loopcounter PRINT 'Value_' + CAST(@insidevalue AS NVARCHAR) + '_' SET @loopcounter = @loopcounter - 1 END I was expecting this block will give the output as below Value_10_ Value_ _ Value_8_ Value_ _ Value_6_ Value_ _