私は奇妙な行動のこの小さな例を設定しました
SET NOCOUNT ON;
create table #tmp
(id int identity (1,1),
value int);
insert into #tmp (value) values(10);
insert into #tmp (value) values(20);
insert into #tmp (value) values(30);
select * from #tmp;
declare @tmp_id int, @tmp_value int;
declare tmpCursor cursor for
select t.id, t.value from #tmp t
--order by t.id;
open tmpCursor;
fetch next from tmpCursor into @tmp_id, @tmp_value;
while @@FETCH_STATUS = 0
begin
print 'ID: '+cast(@tmp_id as nvarchar(max));
if (@tmp_id = 1 or @tmp_id = 2)
insert into #tmp (value)
values(@tmp_value * 10);
fetch next from tmpCursor into @tmp_id, @tmp_value;
end
close tmpCursor;
deallocate tmpCursor;
select * from #tmp;
drop table #tmp;
print
カーソルがテーブル内の新しい行でさえどのように解析するかを観察でき#tmp
ます。order by t.id
ただし、カーソル宣言でコメントを外すと、新しい行は解析されません。
これは意図した動作ですか?