I am trying to bring data from a stored procedure CTE. Now since my stored procedure uses OPEN EXEC I found that the only way which works is using OPENROWSET. So my intended code looks like below:
;with xyz AS
(
select a.*
from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;',
'EXEC [dbo].[usp_GetPayroll]
@StartDate = "1/1/2016",
@EndDate = "4/1/2016",
@OrganizationID = 183,
AS a
)
select * from xyz
So when I try to do this thing I get below error
Msg 11512, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1
The metadata could not be determined because the statement 'WITH EnrollmentChanges AS
(
I did some research and found that when you use the OPENROWSET, it beings back the metadata of only first row. I read something about FMTONLY setting, but it does not work Does someone know any hack around this which works
FYI: Below solution will not work because in that case I will have a dependency on my stored procedure. I do not want to edit this script whenever there is a change in SP. How to get results of stored procedure #1 into a temporary table in stored procedure #2