执行字符串SQL语句,并得到返回结果:
declare @count int
declare @query nvarchar(max)
set @query = 'select @count = COUNT(*) from LoadTest2010.dbo.LoadTestReport'
EXEC sp_executesql @query,
N'@count int OUTPUT',
@count OUTPUT
select @count
将脚本执行结果存储到表里:
DECLARE @T1
TABLE
(
ID bigint
)
insert into @T1
exec('select top 10 ID from YourTbl')
select * from @T1