Unix Technical Forum

resultset of proc in another proc

This is a discussion on resultset of proc in another proc within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, i want to use the result set from a stored proc in another stored proc, for example: create ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 01:31 PM
helmut woess
 
Posts: n/a
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 01:31 PM
SQL
 
Posts: n/a
Default Re: resultset of proc in another proc

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/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 01:31 PM
helmut woess
 
Posts: n/a
Default Re: resultset of proc in another proc

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 01:31 PM
Simon Hayes
 
Posts: n/a
Default Re: resultset of proc in another proc

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 01:31 PM
helmut woess
 
Posts: n/a
Default Re: resultset of proc in another proc

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:32 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com