Solved

Access ResultSet from Stored Procedure in Transact-SQL

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article describes some very basic things about SQL Server filegroups.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

911 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

18 Experts available now in Live!

Get 1:1 Help Now