Solved

Access ResultSet from Stored Procedure in Transact-SQL

Posted on 2004-08-08
3
1,098 Views
Last Modified: 2009-07-29
Hello,

I have a stored procedure which returns a result set, similar to this:

CREATE PROCEDURE myproc AS
  SELECT * FROM mytable
GO

I can easily execute this procedure to get the result set back, and use it via ADO.  However, I don't seem to be able to do anything with it from Transact-SQL.

For example, if I do this:

EXEC myproc

is there some way I can assign a cursor to the result set returned by this command?

Thanks!
0
Comment
Question by:quiTech
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 500 total points
ID: 11747910
You can try something like this :

CREATE FUNCTION myfunc ()
RETURNS @mytab TABLE(col1 integer, col2 float)
AS
BEGIN
insert @mytab
select * from mytable
RETURN
END

then you can access the function as you would a table :
declare mycurs cursor for
select * from dbo.myfunc()
0
 

Author Comment

by:quiTech
ID: 11748797
Perhaps a dumb question... are Functions persistent like stored procedures?
0
 

Author Comment

by:quiTech
ID: 11749450
Never mind :-)
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question