Solved

Access ResultSet from Stored Procedure in Transact-SQL

Posted on 2004-08-08
3
1,085 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

770 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