Why doesn't T-SQL EXEC return decimal numbers?

I have a simple query that I turned into a saved proc:

create procedure GetAmount as declare @amnt decimal(25,2) select @amnt=66666.67 set @amnt = @amnt/3.00 print @amnt return @amnt 

If I type @amnt, it returns 22222.22

But if I use EXEC and assign it to a variable:

 declare @x numeric(25,2) exec @x=SP_GetAmount() print @x 

he returns 22222.00

Does anyone know why?

thanks

+4
source share
1 answer

return returns an integer . Use the output parameter.

 create procedure GetAmount @amnt decimal(25,2) OUTPUT as select @amnt=66666.67 set @amnt = @amnt/3.00 GO 

And to call him:

 declare @x numeric(25,2) exec SP_GetAmount() @amnt = @x OUTPUT print @x 
+8
source

Source: https://habr.com/ru/post/1443390/


All Articles