保存exec的返回值的两种方法:
declare @sql nvarchar(max)
【保存exec的返回值】declare @aa int
set @sql ='select @aa = COUNT(*) from MyTable'
方法1:
create table #aa(c1 varchar(100))
insert #aa exec(@sql)
select * from #aa
方法2:
exec sp_executesql @sql,N'@aa int output',@aa output
select @aa
注意:
@sql必须是nvarchar类型,否则出现sp_executesql 错误 parameter '@statement' of type 'ntext/nchar/nvarchar'
exec sp_executesql 用法可参考
http://blog.csdn.net/jame_peng/archive/2006/11/22/1404248.aspx