SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Export Pivot results to temporary table - Sql Server


Export Pivot results to temporary table - Sql Server

Author
Message
srisagar_p
srisagar_p
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 108
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
LutzM
LutzM
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23899 Visits: 13559
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
srisagar_p
srisagar_p
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 108
Really Thanks for the good solution.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search