Andrew MacNeill
Andrew MacNeill

Reputation: 390

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

Upvotes: 4

Views: 376

Answers (1)

Ed Harper
Ed Harper

Reputation: 21505

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

Upvotes: 8

Related Questions