帮忙看下这么简单的语句会出错呢
declare @m_count int
declare @sql varchar(1000)
set @sql = 'select @m_count=count(*) from table '
exec(@sql )
print @m_count
执行报必须声明变量 '@m_count',我要把count(*)值赋给变量,因为table是动态的。所以要用动态语句
[解决办法]
declare @m_count int
declare @sql nvarchar(1000)
set @sql = N'select @m_count=count(*) from table'
exec sp_executesql @sql,N'@m_count int output',@m_count=@m_count output
print @m_count
这样就可以了