sqlserver 中 如何动态 查询表例如: select count(1) from @n
declare @n varchar(200)
set @n='errip'
select count(1) from @n
这个提示 必须声明表变量 "@n"。
------解决方案--------------------declare @n varchar(200)
set @n='errip'
exec('select count(1) from '+@n)
------解决方案--------------------declare @n nvarchar(200)
declare @num int
set @n='select @num=count(1) from '+@n
exec sp_executesql @n,N'@num int output',@num=@num output
select @num