-- NULL 就是 NULL, 不会用上条记录的值啊, 看下面的测试declare tb cursor local for select id = 2 union all select id = null declare @id int open tb fetch tb into @id while @@fetch_status = 0 begin select @id fetch tb into @id end close tb deallocate tbdeclare tb cursor local for select id = 2 union all select id = null declare @id int open tb fetch tb into @id while @@fetch_status = 0 begin select @id fetch tb into @id end close tb deallocate tb-- 结果: 2 NULL
那只能一个一个用set了
for
select id = 2 union all
select id = null
declare @id int
open tb
fetch tb into @id
while @@fetch_status = 0
begin
select @id
fetch tb into @id
end
close tb
deallocate tbdeclare tb cursor local
for
select id = 2 union all
select id = null
declare @id int
open tb
fetch tb into @id
while @@fetch_status = 0
begin
select @id
fetch tb into @id
end
close tb
deallocate tb-- 结果: 2 NULL