Home All Groups Group Topic Archive Search About

Select Data from a stored procedure from within a stored procedure

Author
28 Jul 2006 8:29 PM
Ed
Hi, hopefully this is an easy question to answer (I don't mind feeling
dumb).

I have a stored procedure that calls a remoted stored procedure that is
selecting data (ie. select name from tblNames)

So my question is: How do I access the data from within my stored
procedure?

(ie. Select * from exec storedProc)


Anyone?  I cannot figure out how to do it.....


¡¡Gracias!!

Ed

Author
28 Jul 2006 8:42 PM
Brian Selzer
try insert...exec to dump the result set into a temp table.
"Ed" <e**@nait.ab.ca> wrote in message
news:1154118554.257671.40680@m73g2000cwd.googlegroups.com...
Hi, hopefully this is an easy question to answer (I don't mind feeling
dumb).

I have a stored procedure that calls a remoted stored procedure that is
selecting data (ie. select name from tblNames)

So my question is: How do I access the data from within my stored
procedure?

(ie. Select * from exec storedProc)


Anyone?  I cannot figure out how to do it.....


¡¡Gracias!!

Ed
Author
28 Jul 2006 9:08 PM
Ed
Is there any way to do it without using the temp table?

Ed

Brian Selzer wrote:
Show quote
> try insert...exec to dump the result set into a temp table.
Author
28 Jul 2006 9:13 PM
Brian Selzer
nope.

Show quote
"Ed" <e**@nait.ab.ca> wrote in message
news:1154120892.284953.262860@i3g2000cwc.googlegroups.com...
> Is there any way to do it without using the temp table?
>
> Ed
>
> Brian Selzer wrote:
>> try insert...exec to dump the result set into a temp table.
>
Author
28 Jul 2006 9:19 PM
Ed
Gad dangit!

Thanks for your help!

Ed


Brian Selzer wrote:
Show quote
> nope.
>
> "Ed" <e**@nait.ab.ca> wrote in message
> news:1154120892.284953.262860@i3g2000cwc.googlegroups.com...
> > Is there any way to do it without using the temp table?
> >
> > Ed
> >
> > Brian Selzer wrote:
> >> try insert...exec to dump the result set into a temp table.
> >
Author
28 Jul 2006 9:20 PM
Anith Sen
One alternative is to create a loopback and use OPENQUERY like:

EXEC sp_serveroption 'data access', TRUE
GO
SELECT *
  FROM OPENQUERY ( Server, 'EXEC usp' ) ;

If you have #temp tables used in your stored procedure, you will have to use
SET FMTONLY OFF ( to set off the attempt to determine the metadata of the
temp table resultset ) within the OPENQUERY like:

SELECT *
  FROM OPENQUERY( Server, 'SET FMTONLY OFF; EXEC usp') ;

--
Anith
Author
28 Jul 2006 9:55 PM
Erland Sommarskog
Ed (e**@nait.ab.ca) writes:
> Hi, hopefully this is an easy question to answer (I don't mind feeling
> dumb).
>
> I have a stored procedure that calls a remoted stored procedure that is
> selecting data (ie. select name from tblNames)
>
> So my question is: How do I access the data from within my stored
> procedure?
>
> (ie. Select * from exec storedProc)

Since this is a remote procedure you could do:

    SELECT * FROM OPENQUERY(SERVER, 'EXEC db.dbo.storedProc')

OPENQUERY is a rowset function that will return the result set from
the other procedure as a table. OPENQUERY will first run the batch
in a sort of NOEXEC-mode to look for resultsets and metadata. This
may fail under some circumstance, for instance if the remote
procedure creates a temp table, as the table is not created in
the NOEXEC mode.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button