alter proc p_getcount
@view varchar(20) ,@count int output
as
exec( 'select @count = count(*) from '+@view)
declare @count int
exec p_getcount 'view_News',@count output
print @count
首先建立存储过程p_getcount 没错
执行 的 时候 就报第四行 @count未声明
怎么解决?? @view是视图名字
------解决方案--------------------------------------------------------
- SQL code
alter proc p_getcount @view varchar(20) ,@count int outputasdeclare @sql nvarchar(800)set @sql=N'select @cnt = count(*) from '+@viewexec sp_executesql @sql, N'@cnt int output', @count output