动态游标

发表于:2007-07-02来源:作者:点击数: 标签:


   
舉個例子,你再根據你的具體情況進行修改:

declare @sqlExec varchar(8000),@tableName varchar(255)
set @tableName = @#sysobjects@#
set @sqlExec = @#declare cursor1 cursor for @# + CHAR(13)
set @sqlExec = @sqlExec + @# select * from @# + @tableName
exec(@sqlExec)
open cursor1
fetch next from cursor1 ---如果要放在变量中请写into <变量列表>
while @@fetch_status = 0
......
fetch next from cursor1 ---如果要放在变量中请写into <变量
end
close cursor1
deallocate cursor1

原文转自:http://www.ltesting.net