T-SQLを使用してストアドプロシージャ出力から一時テーブルを動的に作成するための以下のコードを試してください
declare @ExecutionName varchar(1000) = 'exec [spname] param1,param2 '
declare @sqlStr varchar(max) = ''
declare @tempTableDef nvarchar(max) =
(
SELECT distinct
STUFF(
(
SELECT ','+a.[name]+' '+[system_type_name]
+'
' AS [text()]
FROM sys.dm_exec_describe_first_result_set (@ExecutionName, null, 0) a
ORDER BY a.column_ordinal
FOR XML PATH ('')
), 1, 1, '') tempTableDef
FROM sys.dm_exec_describe_first_result_set (@ExecutionName, null, 0) b
)
IF ISNULL(@tempTableDef ,'') = '' RAISERROR( 'Invalid SP Configuration. At least one column is required in Select list of SP output.',16,1) ;
set @tempTableDef='CREATE TABLE #ResultDef
(
' + REPLACE(@tempTableDef,'
','') +'
)
INSERT INTO #ResultDef
' + @ExecutionName
Select @sqlStr = @tempTableDef +' Select * from #ResultDef '
exec(@sqlStr)