Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to get output from stored procedures


how to get output from stored procedures

Author
Message
sqlblue
sqlblue
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 295
I need to get the output from the stored procedures (50 of them),
and insert into a temp table at each execution of a stored procedure.

Is there a way for me to do this WITHOUT having to pre-define the
temp table (because the columns are all different for each stored procedure
output, otherwise I would have to create 50 temp tables, which I prefer
not having to do it like that).

I am not allowed to change the stored procedures. The stored procedures do not have any parameters, so I cannot use OUTPUT.

if I have to create that many temp tables, then I guess I would have to,
but I just wanted to make sure there is no other better option.

any help/advice would be greatly appreciated.
DCPeterson
DCPeterson
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1129 Visits: 432
Sorry to tell you this, but I think you are in for creating a bunch of temp tables. You can't execute a stored procedure from within a function or a select statement so that rules out being able to use the SELECT...INTO syntax and other than that the table that you are inserting into must already exist.

However, if the stored procs don't have any parameters, why don't you define views and use those? A procedure with no parameters and that simply returns a result set is pretty much a view...

/*****************

If most people are not willing to see the difficulty, this is mainly because, consciously or unconsciously, they assume that it will be they who will settle these questions for the others, and because they are convinced of their own capacity to do this. -Friedrich August von Hayek



*****************/
Matt Miller (#4)
Matt Miller (#4)
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8298 Visits: 18265
Well - temp tables are certainly one way... but they're not the ONLY way.

depending on what you want to do with them, you can set up a "self-linked server" and then use them a bit like table-valued functions and access their output as a table variable.

As in - something like


Select * 
from openquery(MyLocalServer, 'exec mydbo.dbo.myStoredProc @Param=1')



----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
The Dixie Flatline
The Dixie Flatline
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3644 Visits: 6899
Are all the columns in common between the 50 stored procedures? Even if you defined a temp table with enough columns to handle any of the stored procedures, you would still have to define which columns are going to be populated by the output of the stored procedures. For example

create table #temp (many many columns)

insert into #temp (colA,colB,colC)
exec stproc1

insert into #temp (colA,colC,colD,colE)
exec stproc2

insert into #temp (colA,colB,col,C,colD,colE,colF,colG...)
exec stproc99

There just isn't an "automatic" way to avoid all this with stored procedures.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
sqlblue
sqlblue
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 295
Thank you all for responding.

Yes, DCPeterson, creating that many temp tables is what I was afraid of.
I will look into Matt's suggestion, but I'm not sure it would be any easier.
And Quickly Confused is right, there is no auto way to do this
since none of the stored procedure output have the common columns.

This is what I needed to hear before I proceed.
thanks a bunch.
The Dixie Flatline
The Dixie Flatline
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3644 Visits: 6899
Good luck, blue. It's really not difficult, just tedious and time consuming.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
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