declare @cou int declare @i int; set @i=0; while @i<@cou begin select top 1 from testtab where [id] not in (select top (@i) [id] from testtab); set @i=@i+1; end
错了,这样 declare @cou int declare @i int; set @i=0; set @cou=(select count(*) from testtab ); while @i<@cou begin select top 1 from testtab where [id] not in (select top (@i) [id] from testtab); set @i=@i+1; end
不过大部分用游标的地方可以用多行处理来完成同样的功能。
declare @i int;
set @i=0;
while @i<@cou
begin
select top 1 from testtab where [id] not in (select top (@i) [id] from testtab);
set @i=@i+1;
end
declare @cou int
declare @i int;
set @i=0;
set @cou=(select count(*) from testtab );
while @i<@cou
begin
select top 1 from testtab where [id] not in (select top (@i) [id] from testtab);
set @i=@i+1;
end