创建游标
declare myCursor cursor for
select [name] from [table]
//declare @result int
declare @final_result int
打开游标
open myCursor
定义游标结果集的单个对象
declare @subname sysname
//declare @sql nvarchar(500)
执行游标-代码
fetch next from myCursor into @subname
while(@@fetch_status=0) //游标遍历状态:0为成功
begin
set @sql='select count(*) from '+@subname'
exec sp_executesql @sql,N'@a int output',@result output //sql 获得exec的值
fetch next from myCursor into @subname
end
关闭游标
close myCursor
deallocate myCursor
所有评论(0)