DROP TABLE ##Temp
DECLARE @dtmFrom VARCHAR(60) = '2020-12-01 00:00:00', @dtmTo VARCHAR(60) = '2020-12-02 23:59:59.997',@numAdmDscTransID VARCHAR(60) =247054
declare @procname nvarchar(255) = 'spGetCashUnpaidBills',
@procWithParam nvarchar(255) = '[dbo].[spGetCashUnpaidBills] @dtmFromDate= ''' +@dtmFrom+ ''' ,@dtmToDate= ''' +@dtmTo+''',@numCompanyID=1,@numAdmDscTransID='+ @numAdmDscTransID +',@tnyShowIPCashSchemeBills=1',
@sql nvarchar(max),
@tableName Varchar(60) = 'Temp'
set @sql = 'create table ##' + @tableName + ' ('
begin
select @sql = @sql + '[' + r.name + '] ' + r.system_type_name + ','
from sys.procedures AS p
cross apply sys.dm_exec_describe_first_result_set_for_object(p.object_id, 0) AS r
where p.name = @procname
set @sql = substring(@sql,1,len(@sql)-1) + ')'
execute (@sql)
execute('insert ##' + @tableName + ' exec ' + @procWithParam)
end
SELECT *FROM ##Temp