while ループ内のテーブル変数が他の変数のように動作しない理由を知りたいです。テーブル変数は一度だけ作成され、ループ全体で使用されます。ただし、ループが増加するたびに他の変数が初期化されます。
詳細については、以下のコードを確認してください
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
--delete from @temptable
set @tt=@tt-1
end
これはバグですか??