declare @count int
declare @total int
set @total=0
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
set @total = @total + @count
print @tablename
print @count
end
fetch next from mycursor into @tablename
end
print @total
close mycursor
deallocate mycursor
带输出的游标
最新推荐文章于 2023-03-03 14:30:33 发布