sql数据库中带输出的游标写法

发布时间:2019-12-20编辑:脚本学堂
有关sql server数据库中带输出的游标写法,有关sql数据库游标语句的例子,需要的朋友参考下。

例子,sql数据库带输出的游标。
 

复制代码 代码示例:

declare @count int
declare @tablename varchar(100)
declare @sql nvarchar(4000)
declare mycursor cursor for
select name from sysobjects where name like 'test____'
open mycursor
fetch next from mycursor into @tablename
while(@@FETCH_STATUS=0)
begin
set @sql='select @count=COUNT(*) from ' + @tablename
exec sp_executesql @sql,N'@count int output' ,@count=@count   output  

--print @tablename
if(@count=0)
begin
print @tablename
print @count

end

fetch next from mycursor into @tablename 
end
close mycursor
deallocate mycursor