Dear All,
This is a query surrounding a problem I encountered
yesterday.
In SQL Server, it is possible to write a procedure that
has one or more select statements in it.
The results from these select statements will all be
individually returned to SQL Query Analyser where they
can be viewed in "grid" views. Also, these individual
results sets can be consumed by eg ADO.NET by stepping
through each results set in turn and processing the
respective results.
My question is, can you do the same in a SQL Server
procedure? ie:
Create Procedure Proc1
AS
begin
select Col1, COl2
from Table1
select Col1, Col2, Col3
from Table2
end
Create Procedure Proc2
AS
begin
exec Proc1
end
Can both/either of the results sets from Proc1 be
consumed by the calling procedure Proc2?
I can see that you could design the procedures up-
front to do almost anything without consuming the
result sets in this way, but if the procedures
returning the results sets are already built and
in use in other places (for instance in client code),
can they be re-used on server-side SQL procedures?
Thanks in anticipation!
Paul. 5 2914
In the example you have, the result to the caller of Proc 2 will see
the two results of the Proc1 procedure. As far as Proc2 "consuming" the
results of Proc1, there is no operation happening on the results in
your example.
Are you asking if you could return multiple tables from another proc
and do some manipulation on them, before you return those to the caller?
Thanks for the quick reply! As far as Proc2 "consuming" the results of Proc1, there is no operation happening on the results in your example.
That is because I don't know how to represent it at
the moment - hopefully that's where you come in! ;-)
Are you asking if you could return multiple tables from another proc and do some manipulation on them, before you return those to the caller?
yes - whether I can return and manipulate one or more
data sets into a calling procedure, *without* changing my
original (called) procedures which take a form similar to:
Create Procedure Proc1
AS
begin
select Col1, COl2
from Table1
select Col1, Col2, Col3
from Table2
end
I hope this makes sense...
Thanks!
Paul.
You can use the NextResult method of a SqlDataReader object to process
multiple result sets returned from a single command. For example:
SqlDataReader myDataReader = myCommand.ExecuteReader();
while(true)
{
while(myDataReader.Read())
{
ProcessMyResults();
}
if(!myDataReader.NextResult()) break;
}
myDataReader.Close();
--
Hope this helps.
Dan Guzman
SQL Server MVP
<p_**********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Thanks for the quick reply!
As far as Proc2 "consuming" the results of Proc1, there is no operation happening on the results in your example.
That is because I don't know how to represent it at the moment - hopefully that's where you come in! ;-)
Are you asking if you could return multiple tables from another proc and do some manipulation on them, before you return those to the caller?
yes - whether I can return and manipulate one or more data sets into a calling procedure, *without* changing my original (called) procedures which take a form similar to:
Create Procedure Proc1 AS begin select Col1, COl2 from Table1
select Col1, Col2, Col3 from Table2 end
I hope this makes sense...
Thanks!
Paul.
On 8 Dec 2004 04:17:30 -0800, p_**********@hotmail.com wrote: Thanks for the quick reply!
As far as Proc2 "consuming" the results of Proc1, there is no operation happening on the results in your example.
That is because I don't know how to represent it at the moment - hopefully that's where you come in! ;-)
Are you asking if you could return multiple tables from another proc and do some manipulation on them, before you return those to the caller?
yes - whether I can return and manipulate one or more data sets into a calling procedure, *without* changing my original (called) procedures which take a form similar to:
Create Procedure Proc1 AS begin select Col1, COl2 from Table1
select Col1, Col2, Col3 from Table2 end
I hope this makes sense...
Thanks!
Paul.
The INSERT INTO ... EXEC command can let a T-SQL batch (or procedure)
consume ONE resultset from another procedure, but not multiple resultsets.
Sorry.
Dan's method shows how to consume multiple resultsets from a .NET client,
but not from another stored procedure.
(p_**********@hotmail.com) writes: My question is, can you do the same in a SQL Server procedure? ie:
Create Procedure Proc1 AS begin select Col1, COl2 from Table1
select Col1, Col2, Col3 from Table2 end
Create Procedure Proc2 AS begin exec Proc1 end
Can both/either of the results sets from Proc1 be consumed by the calling procedure Proc2?
When you call Proc2, the result sets go to the client. You can use
INSERT/EXEC to catch the data, but it only works if the result sets
are equally structures. (I think it works then, I am not sure.)
Anyway, I have an article on my web site, which discusses this in detail: http://www.sommarskog.se/share_data.html.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jamiemcc |
last post by:
Hi,
I would like to have 1 stored procedure call another stored procedure
(which contains multiple select statements) and then be able to access
the 3 result sets.
Example
Create Procedure ....
|
by: Jegg |
last post by:
I wrote a web app using an ASP front end (not .NET) connecting to a SQL
Server 2000 (no SP) back end. Both the web server and the database
server are Windows 2003 boxes. The app was running fine...
|
by: wxbuff |
last post by:
I have a report based on our product names that consists of two parts.
Both insert data into a temporary table.
1. A single grouped set of results based on all products
2. Multiple tables based...
|
by: Stanley Sinclair |
last post by:
I have a need to return multiple result sets from a stored procedure.
Want that SP to call others to get the data.
Win2003, db2 8.1.5.
Can't figure out how to handle open cursors, and return...
|
by: Randy Foster |
last post by:
We have a stored procedure (on DB2 8.1 FP5) that returns multiple
result sets which we are calling from Java (WebSphere 5.0.2.8).
We can call the stored procedure from the DB2 command line...
|
by: Patrick Olurotimi Ige |
last post by:
When i run the code below with stored proc :-
I get only the first table results :-"templates"
even if i fill the dataset with another table for example
category,pages etc..
Any ideas?
...
|
by: alex.mcshane |
last post by:
Hi - I would be grateful for any knowledge regarding the following.
Whilst QAing Stored Procedures developed by colleagues, I noticed the
following 'superflous' parameter specifications:-
1)...
|
by: Chris |
last post by:
Hi,
I created a VB SQL CRL Stored procedure for calculating a value. Value
is returned as below
Using sConn4 As New SqlConnection("context connection=true")
sConn4.Open()
scmd = New...
|
by: Jeremy Chapman |
last post by:
I've writtin a very simple web service in axis which returns an array of
classes.
I consume it in a .net app. When receiving the response, my .net app
generates an error "Cannot assign object...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |