sql-servert-sqlsql-server-2008

Put stored procedure result set into a table variable without specifying its schema


I have a stored procedure with many parameters.

I want to insert (or maybe select) like this:

INSERT INTO @TEMP_TABLE
    EXECUTE STORED_PROCEDURE

without defining the schema of @TEMP_TABLE.


Solution

  • You cannot do this with a @tablevariable.

    The work around in the link posted by Joe uses SELECT ... INTO.

    This is not currently supported by table variables (and won't ever be from the response to this connect item) as the schema for table variables needs to be known at compile time.