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


How to save results of a procedure with more than one result set


How to save results of a procedure with more than one result set

Author
Message
Pavel Sinkevich
Pavel Sinkevich
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 181
Comments posted to this topic are about the item How to save results of a procedure with more than one result set
Paul White
Paul White
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20470 Visits: 11359
You can use the context connection to get the server name. Create a non-context connection from that information and then use bulk copy.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3906 Visits: 4408
For each table name: if we already have such a table in the database, drop it ...

... and say goodbye to a concurrent process (if any) :-)
Not so good, I would say.
Paul White
Paul White
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20470 Visits: 11359
vk-kirov (9/6/2012)
For each table name: if we already have such a table in the database, drop it ...

... and say goodbye to a concurrent process (if any) :-)
Not so good, I would say.

An improvement might be to limit the target tables to temporary tables. That's the scenario I would expect this sort of idea to be used with. On the other hand, we also have MARS...but I guess that's another story.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Pavel Sinkevich
Pavel Sinkevich
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 181
SQL Kiwi (9/6/2012)
vk-kirov (9/6/2012)
For each table name: if we already have such a table in the database, drop it ...

... and say goodbye to a concurrent process (if any) :-)
Not so good, I would say.

An improvement might be to limit the target tables to temporary tables. That's the scenario I would expect this sort of idea to be used with. On the other hand, we also have MARS...but I guess that's another story.


Temporary tables could be a good improvement if we only need resulting tables in same session. It all depends on your requirements.
If we don't need to drop tables at all, we can just remove corresponding code from the procedure. In my case, corresponding tables didn't exist before procedure execution, and creating those tables by hands could be huge waste of time because I had lots of stored procedures to process.
Paul White
Paul White
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20470 Visits: 11359
Pavel Sinkevich (9/6/2012)
Temporary tables could be a good improvement if we only need resulting tables in same session.

Global temporary tables e.g. ##Fish :-)



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
richardd
richardd
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3180 Visits: 648
Nice - a potential SQL injection vulnerability right inside your database! :-P



bens4lsu
bens4lsu
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 58
That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.
ZZartin
ZZartin
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3686 Visits: 9406
bens4lsu (9/6/2012)
That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.


I was wondering this too and since the solution requires creating a new stored procedure anyways why not just do it all in the same stored procedure?
Pavel Sinkevich
Pavel Sinkevich
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 181
ZZartin (9/6/2012)
bens4lsu (9/6/2012)
That seems like a lot of work, when you could modify the original stored procedure to save the multiple result sets to a temp table and then return them all as one result set. Of course, there might be a reason that you can't update the procedure, but it seems like that would be the preferable course.


I was wondering this too and since the solution requires creating a new stored procedure anyways why not just do it all in the same stored procedure?

In my case - because I had limited access to the database and couldn't modify any legacy code.
As I noted in the article, this procedure can be used for ETL process from poorly designed databases, were we have lots of multiple result set procedures, and we don't want to modify each of them.
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