Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is T-SQL EXEC not returning decimals?

I have a simple query that I've turned into a stored 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 print @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

it returns 22222.00

Anyone know why?

Thanks

like image 419
Andrew MacNeill Avatar asked Feb 18 '23 15:02

Andrew MacNeill


1 Answers

return returns an integer. Use an output parameter.

create procedure GetAmount 
    @amnt decimal(25,2) OUTPUT
as

select @amnt=66666.67 
set @amnt = @amnt/3.00

GO

And to call it:

declare @x numeric(25,2)
exec SP_GetAmount() @amnt = @x OUTPUT
print @x
like image 167
Ed Harper Avatar answered Mar 05 '23 14:03

Ed Harper