I am wondering why table variables inside a while loop do not behave like other variables. Variable tables are created only once and will be used throughout the cycle. but other variables get initialized every time the loop grows.
Check out the code below for more information.
declare @tt int
set @tt =10
while @tt>0
begin
declare @temptable table(id int identity(1,1),sid bigint)
insert into @temptable
select @tt union all
select @tt + 1
select * from @temptable
set @tt=@tt-1
end
- this is mistake?
source
share