Solved

Access ResultSet from Stored Procedure in Transact-SQL

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now