存储过程得到值的问题
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 output
as
declare @sql nvarchar(800)
set @sql=N'select @cnt = count(*) from '+@view
exec sp_executesql @sql, N'@cnt int output', @count output