Solved

Access ResultSet from Stored Procedure in Transact-SQL

Posted on 2004-08-08
3
1,108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…

632 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