I have a "dynamic" stored procedure with multiple input parameters, which returns some columns as output and an unknown count of result columns.
I want to execute this stored procedure and insert result into #temp_Table
without any change to the stored procedure itself.
Note:
- I don't know the count of result columns
- The stored procedure shown below just an example
Can anyone help me to solve my problem?
Thanks a lot.
CREATE PROCEDURE [dbo].[GetDBNames]
@id INT
AS
BEGIN
DECLARE @QUERY NVARCHAR(max)=''
SET @QUERY = @QUERY +
'SELECT name, database_id FROM sys.databases
WHERE database_id = ' + CAST(@id AS VARCHAR(max)) + ''
EXEC (@QUERY)
END