用TOP代替一般游标
没事发个帖,代表我还存活着。
以前弄的用TOP取值来代替一般游标取值的法子,效率如何,没经过测试......有个前提,得有个排序用的列,如ID
Declare @o Bigint,
@n Varchar(256),
@h Int
Set @o=0
Set @n=''
Set @h=0
Select @h=Count(*) From table1
While @h>0
Begin
Set Rowcount @h
Select ID,A,B
Into #temp
From table1
order by ID desc
Select Top 1 @o=A,@n=B
From #temp
order by ID
Set @h=@h-1
Drop Table #temp
Set rowcount 0
End