I have a stored procedure that generated a query string and then executes it with
EXECUTE SP_EXECUTESQL @Query
The query, e.g., is: Select Name, Age from tableA
, so very simple.
But how to get the result set back from the SP_EXECUTESQL
(into a variable?) and then return it as result set in my stored procedure?
Best Answer
You could use a table variable to hold the results of the dynamic SQL call until you are ready to exit the stored procedure. Just before returning from the stored procedure, select the data from the table variable.