1

I have the next T-SQL code:

DECLARE @A CHAR(1)
DECLARE @B CHAR(10)
DECLARE @C DECIMAL
DECLARE @D CHAR(1)

SET @A = 'S'
SET @B = '2015-03-23'
SET @C = 1
SET @D = 'P'

EXEC('CALL DATA_COLLECTOR(?,?,?,?)',@A, @B, @C, @D) at LINKED_SERVER_10

PRINT @D

@D is an input-ouput variable.

After running the code, the variable @D gets a result set (5 rows, 10 columns).

How can I copy the result set contained in @D to another table in my database?.

Thanks in advance.

3
  • 1
    What does "the variable gets a table" mean? Commented Mar 25, 2015 at 20:50
  • The output parameter gets a result set of 5rows x 10columns. Commented Mar 25, 2015 at 20:54
  • 1
    Still don't know how you have defined an output parameter that accepts a char(1) as input but outputs a "result set"... can you show the stored procedure code so we don't have to try to guess what it does? Commented Mar 25, 2015 at 21:02

2 Answers 2

1

To create a new table from the variable, use

SELECT * INTO newTable FROM @D

To put the data into an existing table, use

INSERT INTO existingTable SELECT * FROM @D
Sign up to request clarification or add additional context in comments.

Comments

0

Your output cannot be CHAR(1)

If you ignore @D and just want to store the result set of your procedure into a table, then you have few choices to do:

  1. Table has been created before

    CREATE TABLE #Table (Field1 INT, Field2 VARCHAR(50));
    INSERT INTO #Table
    EXEC yourProcedure
    

To see the result

    SELECT *
    FROM #Table
  1. Create table at runtime using OPENROWSET

    sp_configure 'Show Advanced Options', 1
    GO
    RECONFIGURE
    GO
    sp_configure 'Ad Hoc Distributed Queries', 1
    GO
    RECONFIGURE
    
    SELECT * INTO #Table
    FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
    'EXEC tempdb.dbo.yourProcedure')
    

To see the result

    SELECT *
    FROM #Table

1 Comment

Yes, I was wrong!, the @D parameter just give me a char, Thanks for the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.