I have a stored procedure like this:
Select @totalMoney*@bonusPercent/100
How i can return value from procedure and assign it to the开发者_运维知识库 varible? i mean something like:
SET @myVarible = EXEC MyStoredProcedure @param1, @param1;
Use an output
variable, return only works with integers
example
create procedure prTest @id int, @id2 decimal(20,10) output
as
select @id2 = @id + 1
go
now call it like this
declare @Test decimal(20,10)
exec prTest 5,@Test output
select @Test
output
6.00000000
Within the stored procedure just use
RETURN @X
@X
must be an integer data type.
Return codes are normally used for status codes though. An output parameter may be a better choice dependant upon what you are doing exactly.
Declare the parameter as OUTPUT
CREATE PROCEDURE dbo.MyStoredProcedure
@param1 INT,
@myVarible DECIMAL(10,4) OUTPUT
AS
...
and call it as
EXEC dbo.MyStoredProcedure @param1, @myVarible OUTPUT;
精彩评论