Saturday, 25 May 2013
     
AUSQLUG Forums Home   Search   Login   Register   Member List  
SQL Server 2000 Forums  > SQL Server - General  > Adding results of called stored proc. which returns value as row  
 
Display using:  
Previous Thread :: Next Thread 
 Author Thread: Adding results of called stored proc. which returns value as row
IP is not online. Last active: 12/12/2006 2:39:41 PM IP
Top 25 Poster
Joined: 12 Apr 2005
Total Posts: 47
 
Adding results of called stored proc. which returns value as row
Posted: 23 Feb 2006 08:36 PM
I am calling one stored procedure from another
There are no output parameters in test2 procedure

1st proc
-------------------------------
create proc test1 as
declare @TotalSell float
exec @TotalSell= test2 '1,'2','3'
select @TotalSell=@TotalSell+100
print @TotalSell
------------------------------------------------


2nd Proc
-----------------------------------------
create proc test2 (
@p1 Int,
@p2 real,
@p3 Int
)
AS

SET @price = @p1+@p2+@p3
/* return total price */
SELECT @price AS [Total Price]
---------------------------------------------------


2nd proc gives result '6' as row but not as output parameter.


i want the result of proc test1 as 100+6=106.

But now it is returning as only 100.

It is not adding 6 into 100. The reason is test2 is returning row and not value.

I can't change the proc test2.

I can change only proc test1.

Can you please provide any solution?

Thanks,
IP




philcart is not online. Last active: 7/01/2013 4:04:01 PM philcart
philcart.blogspot.com
Top 25 Poster
Forum Moderator
Joined: 20 Jul 2004
Total Posts: 345
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 08:58 AM
Best solution would be to change the test2 procedure, but as you can't do that, try this quick work around.


create proc test1 as
declare @TotalSell float
create table #t ( pr int )

insert into #t
exec test2 '1','2','3'

SELECT @totalsell = pr FROM #t

select @TotalSell=@TotalSell+100
print @TotalSell

GO



Thanks
Phill

Colt 45 - the original point and click interface ;)
http://philcart.blogspot.com/
IP is not online. Last active: 12/12/2006 2:39:41 PM IP
Top 25 Poster
Joined: 12 Apr 2005
Total Posts: 47
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 01:30 PM
Hi Philip,

Your solution is correct but I don't want to use this solution as this will not give less response time for executing. I want to call this proc for more than 10000 times in one shot.

Can you please suggest me any other solution?

Thanks,
IP
robf is not online. Last active: 10/06/2010 12:59:05 AM robf
msmvps.com
Top 25 Poster
Joined: 23 Feb 2005
Total Posts: 57
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 01:38 PM
Have you tried using a table variable instead of a temporary table? That should be much quicker.
IP is not online. Last active: 12/12/2006 2:39:41 PM IP
Top 25 Poster
Joined: 12 Apr 2005
Total Posts: 47
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 01:43 PM
I have tried this but I think table variable can't be created with procedures.
May be I am not aware how to create table varibale with proc.

Can you please write the query for table variable.
philcart is not online. Last active: 7/01/2013 4:04:01 PM philcart
philcart.blogspot.com
Top 25 Poster
Forum Moderator
Joined: 20 Jul 2004
Total Posts: 345
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 02:03 PM
Creating a table variable is much the same as creating a temp table,

instead of


CREATE TABLE #t (pr int)


you have


DECLARE @t TABLE (pr int)



Thanks
Phill

Colt 45 - the original point and click interface ;)
http://philcart.blogspot.com/
robf is not online. Last active: 10/06/2010 12:59:05 AM robf
msmvps.com
Top 25 Poster
Joined: 23 Feb 2005
Total Posts: 57
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 02:06 PM
Just like this:

create proc test1 as
declare @TotalSell float
declare @t table ( pr int )

insert into @t
exec test2 '1','2','3'

SELECT @totalsell = pr FROM @t

select @TotalSell=@TotalSell+100
print @TotalSell



The only change is the 'declare' instead of 'create'.

Oh, it's worth noting that pre-SQL05, you couldn't insert the results of a stored procedure into a table variable.

And I'm not sure about whether it would actually be faster this way. Worth doing a couple of tests.

Rob
IP is not online. Last active: 12/12/2006 2:39:41 PM IP
Top 25 Poster
Joined: 12 Apr 2005
Total Posts: 47
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 03:52 PM
Thanks
IP
IP is not online. Last active: 12/12/2006 2:39:41 PM IP
Top 25 Poster
Joined: 12 Apr 2005
Total Posts: 47
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 03:54 PM
Is there anything like

select @TotalSell=[Total Sell] from ( exec test2 '1','2','3' ) a
robf is not online. Last active: 10/06/2010 12:59:05 AM robf
msmvps.com
Top 25 Poster
Joined: 23 Feb 2005
Total Posts: 57
 
Re: Adding results of called stored proc. which returns value as row
Posted: 24 Feb 2006 03:58 PM
Would be nice, but no, unfortunately not.
Previous Thread :: Next Thread 
Page 1 of 1
 
AUSQLUG Forums  > SQL Server 2000 Forums  > SQL Server - General  > Adding results of called stored proc. which returns value as row