|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting value from SPI have a stored procedure with one param and gives me one result. It takes a
SKU varcahr and sends back it's price (I don't use output param). I need to call this procedure from within another procedure several times (cursor loop), something like this mycursor fetch @sku set @myprice = exec mySP @sku do something fetch next Is it possible, if yes, what should be the syntax to call mySP Thanks in advance An Output parameter is the proper way to do this but you can try this:
EXEC @myprice = [dbo].[mySP] @sku -- Show quoteAndrew J. Kelly SQL MVP "SalamElias" <eliassal@online.nospam> wrote in message news:4CFF8837-D43B-40DC-92A5-62A737A25F04@microsoft.com... >I have a stored procedure with one param and gives me one result. It takes >a > SKU varcahr and sends back it's price (I don't use output param). > I need to call this procedure from within another procedure several times > (cursor loop), something like this > mycursor fetch @sku > set @myprice = exec mySP @sku > do something > fetch next > Is it possible, if yes, what should be the syntax to call mySP > > Thanks in advance On Fri, 25 Nov 2005 12:57:34 -0800, SalamElias wrote:
>I have a stored procedure with one param and gives me one result. It takes a Hi SalamElias,>SKU varcahr and sends back it's price (I don't use output param). >I need to call this procedure from within another procedure several times >(cursor loop), something like this >mycursor fetch @sku >set @myprice = exec mySP @sku >do something >fetch next >Is it possible, if yes, what should be the syntax to call mySP > >Thanks in advance The best you can do is to rewrite the stored procedure's logic to handle all rows at once, then also change the "do something" to "do something for all rows at once". SQL Server is optimized for set-based processing; row by row processing is slower in at least 99% of all cases. If that's not possible in your case, then at least rewrite the procedure to use an output parameter. The return value of a stored procedure can only be an integer, since the return value is intended to be used to return a success/failure status only. A price will usually not be an integer. Then, use EXEC mySp @sku, @result = @myprice OUT Or, if you insist on kluding a price in an integer return value: EXEC @myprice = mySp @sku Best, Hugo -- (Remove _NO_ and _SPAM_ to get my e-mail address) |
|||||||||||||||||||||||