Return Dynamic SQL Results to a Table

  • Hi,

    I have an unusal query which I am looking more for general advice than specific code.

    I have a stored procedure which creates a dynamic pivot statement as the number of columns for the output is unknown.

    The results of the pivoted query needs to be returned into a table for further analysis.

    Usually I would have created a destination table, then inserted the rows using something like:

    INSERT INTO #temp_resuts

    EXEC (@sqlStmt)

    The problem is that I don't know how many columns there will be to create the temp table first so I though SELECT INTO would make more sense as it creates the table during the insert, the problem is I am not sure if this is possible.

    Is there anyway of doing something like

    SELECT * INTO #temp_resuts FROM (EXEC (@sqlStmt))

    If anyone can help it would be most appreciated.

    MCITP SQL 2005, MCSA SQL 2012

  • This was removed by the editor as SPAM

  • Thanks for the help XML is not my forte but it least gives me a head start. Thank You.

    MCITP SQL 2005, MCSA SQL 2012

  • Hi,

    Option two works well. Thanks.

    MCITP SQL 2005, MCSA SQL 2012

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply