473,698 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resultset of proc in another proc

Hello,

i want to use the result set from a stored proc in another stored proc, for
example:

create stored procedure proc1 (@x int) as
declare @tbl (y1 int, y2 int)
insert into @tbl values(@ * @x, @x * @x * @x)
select * from @tbl
GO
--
create stored procedure proc2 (@x int) as
declare @tbl (y1 int, y2 int)
while @x > 0 begin
insert into @tbl select (exec proc1 @x) <-- this is my problem
set @x = @x - 1
end
select * from @tbl
GO
--

I know i could use output parameters. But i want to know if something is
possible with SQL-Server?

thanks,
Helmut
Oct 4 '05 #1
4 1800
SQL
Create a temp table in the first proc (2) and populate that table in
the second proc (1)
Like this

create stored procedure proc1 (@x int) as
insert into #temp values(@ * @x, @x * @x * @x)
select * from @tbl
GO
--
create stored procedure proc2 (@x int) as
declare @tbl (y1 int, y2 int)
create #temp (y1 int, y2 int)
while @x > 0 begin
(exec proc1 @x) <-- this is my problem
set @x = @x - 1
end
insert into @tbl
select * from #temp

select * from temp
---or select * from @tbl -- you can eliminate @tbl in this proc
GO
I don't know why you are calling the second proc you can do all this
stuff in 1 proc like this
-------------------------------------------------------------------------------
create stored procedure proc2 (@x int) as
declare @tbl (y1 int, y2 int)
while @x > 0 begin
insert into @tbl
values(@ * @x, @x * @x * @x)
set @x = @x - 1
end
select * from @tbl
GO

http://sqlservercode.blogspot.com/

Oct 4 '05 #2
Am 4 Oct 2005 07:23:52 -0700 schrieb SQL:
Create a temp table in the first proc (2) and populate that table in
the second proc (1)
Like this

create stored procedure proc1 (@x int) as
insert into #temp values(@ * @x, @x * @x * @x)
select * from @tbl
GO


That doesn't help immediately. Because both procs can be called
independently by the client program. But i can put the working part in a
third proc which is called by proc1 or proc2, then i can use your
suggestion.
And i can't put everything in one proc, because in my real application the
first proc should calculate different values for one specific contract, the
second proc should calculate the values for a group of contracts (using
proc1) and present the result in a little different output.

But i am still very interested if it is possible without output parameters
and populated tables.

thanks,
Helmut

Oct 4 '05 #3
helmut woess wrote:
Hello,

i want to use the result set from a stored proc in another stored proc, for
example:

create stored procedure proc1 (@x int) as
declare @tbl (y1 int, y2 int)
insert into @tbl values(@ * @x, @x * @x * @x)
select * from @tbl
GO
--
create stored procedure proc2 (@x int) as
declare @tbl (y1 int, y2 int)
while @x > 0 begin
insert into @tbl select (exec proc1 @x) <-- this is my problem
set @x = @x - 1
end
select * from @tbl
GO
--

I know i could use output parameters. But i want to know if something is
possible with SQL-Server?

thanks,
Helmut


This is a good summary of the options:

http://www.sommarskog.se/share_data.html

Simon
Oct 5 '05 #4
Am Wed, 05 Oct 2005 01:54:33 +0200 schrieb Simon Hayes:
helmut woess wrote:
Hello,

i want to use the result set from a stored proc in another stored proc, for
example:

create stored procedure proc1 (@x int) as
declare @tbl (y1 int, y2 int)
insert into @tbl values(@ * @x, @x * @x * @x)
select * from @tbl
GO
--
create stored procedure proc2 (@x int) as
declare @tbl (y1 int, y2 int)
while @x > 0 begin
insert into @tbl select (exec proc1 @x) <-- this is my problem
set @x = @x - 1
end
select * from @tbl
GO
--

I know i could use output parameters. But i want to know if something is
possible with SQL-Server?

thanks,
Helmut


This is a good summary of the options:

http://www.sommarskog.se/share_data.html

Simon


very good information!

thank you very much,
Helmut
Oct 5 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2067
by: June Moore | last post by:
Hi, I would like to write a stored procedure that returns a resultset. e.g. select student_id, student_subject, subject_marks from student_results where student_class_no = ? The input parameter is student_class_no (see ? as per above SQL). The output is a resultset, with each result consisting of student_id,
1
4295
by: rafikki3 | last post by:
I have a java web application that is using the db2jcc driver to get a connection to a DB2 database that is located on an RS 6000 server. The here is a portion of the code that is giving me a problem. rs is an ResultSet object instantiated by the following... detailStmt = vmCon.prepareStatement(detailSelect); detailResults = detailStmt.executeQuery();
2
10618
by: Twan Kennis | last post by:
Question: How do I pass a returning resultset from a nested Stored Procedure (which opens a cursor including option "WITH RETURN TO CALLER") as a returning resultset from it's own? When I execute the top-level Stored Procedure, it executes succesfully, but without any resultset. ========================================================== CREATE PROCEDURE sp_executesql(sqltxt CLOB(2M))
8
2076
by: CSDunn | last post by:
Hello, I have a situation in which I need to address three SQL Server 2000 Stored Procedure parameters in the OnClick event of an Option Group. The Option Group lives on an Access 2000 ADP form. In another situation where I had to set the RowSource of a combo box based on a parameter value that was delivered to a proc from another combo box, I did this: Private Sub FirstCombo_AfterUpdate()
4
4451
by: _link98 | last post by:
Problem: java ResultSet cursor from SQL/PL stored-procedure is FORWARD_ONLY. Is it possible to have ResultSet cursors from SQL/PL procedures to scroll forward and backwards? Perhaps I am missing something. Environment: client UDB 8.1 FP9a on Win32, server UDB 8.1 FP9a on Solaris 8 (64BIT). The JDK version on the WinXP client is
3
15791
by: mandible | last post by:
I'm trying to call one stored procedure inside another. I was wondering if this is possible Some ideas I was toying with is putting the first stored procedure inside of a temp table but haven't been able to get this idea to work.
3
6386
by: satkins | last post by:
Hello everyone. I've been trying to find if this is even possible but nothing I've found has really helped. I've got a stored proc with a few input parameters and one output parameter. I would like to call this proc from another proc and have proc 2 return the result of proc1 as a column. Some thing like this create procedure Proc1 @Input1 numeric, @Input2 varchar(20), @Input3 money output as Select @Input3 = Amount from...
1
1443
by: brutusram | last post by:
I am trying to execute SP that has another SP in it that is being passed multiple values. I want to stay away from cursors but I cannot find another way to do this in 2005. BEGIN 1st STORED PROC ...running the 1st Proc info.... DECLARE @id UNIQUEIDENTIFIER SELECT @id=id
0
1563
by: av~ | last post by:
Hi All , I am trying to call a db2 stored proc with cursor open from my java code but it always returns me null results though it executes fine when I call the procedure from the command line Java code.................... CallableStatement stmt3 = EyeHibernateApp.getHibernateSession().connection().prepareCall("{call answers_select_id( ? )}"); stmt3.setString(1,20); stmt3.execute();
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7729
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.