Export Pivot results to temporary table - Sql Server

  • Hi All,

    Please give me an idea to export the pivot results to a temporary table in Sql Server.

    Requirements:

    1) Donno how many columns after pivot done in sql server

    Do we have any solution in sql server to save or export this pivoted results to a sql table.

    Waiting for your good responses,

    Thanks & Regards,

    Sri Sagar. P

  • If the number of columns is unknown, I would use the DynamicCrossTab approach instead of PIVOT.

    Please see the two related articles referenced in my signature.

    Since you most probably need to use Dynamic SQL, you cannot use a normal temp table (since it would be out of scope). There are two options I can think of:

    1) create a global temp table in the sproc that calls the dynamic SQL and insert into that global temp table (use INSERT INTO ##GlobalTempTable SELECT... inside the dynamic SQL part) or

    2) create a permanent table and insert into that table (you should consider concurrent inserts, so a unique sprocID column could be used to identify what values belong to a specific sproc.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Really Thanks for the good solution.

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

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