I have something like this:
Create Procedure GetStockNumber
@Barcode int
As
Select CodStock from TBL_Stock
Where barcode = @barcode
(Let’s say the result of the Select is 8 for example)
OK simple 😀
BUTTT! I want to use the result (8) of that SP (GetStockNumber) in another SP.
Something like this:
Create procedure Blablabla
@Quantity int
As
Update TBL_Stock
Set Quantity = Quantity - @Quantity
Where CodStock = [THE RESULT OF THE SP (GetStockNumber)]
In this case it would be 8 for this example.
So how can I do this?
**
Solved using the 2º method mentioned by Icarus
**
You have a couple of different options:
1) Return an output parameter from the first stored procedure.
to use it:
2) Convert the stored procedure to a function that returns a value.
To use it: