2

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:

  1. I don't know the count of result columns
  2. 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
user3588552
  • 311
  • 1
  • 3
  • 12

0 Answers0