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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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/ |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |