Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Export Pivot results to temporary table - Sql Server Expand / Collapse
Author
Message
Posted Wednesday, December 21, 2011 3:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 13, 2014 4:40 AM
Points: 13, Visits: 90
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
Post #1224977
Posted Wednesday, December 21, 2011 4:15 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:39 AM
Points: 6,826, Visits: 13,280
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
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #1225009
Posted Wednesday, December 21, 2011 6:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 13, 2014 4:40 AM
Points: 13, Visits: 90
Really Thanks for the good solution.
Post #1225062
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse