Stored Procedure won't return decimal


Why won't this stored procedure return a decimal and what can I do to get a decimal back?

--Stored Procedure
alter procedure rjmTest6 (@z decimal(4,2) output)
As
      Set NoCount On
      Declare @x decimal(4,2)
      Declare @y decimal(4,2)
      
            Set  @x = 3.1
            Set  @y = 4.5
            Set  @z = @x / @y
      
      print @z
Return

--Calling routine
declare @a decimal(5,1)
exec       @a = rjmTest6 @a
print       @a

--Results
0.69
0.0



scollegeAsked:
Who is Participating?
 
Scott PletcherSenior DBACommented:
Yes, I left off OUTPUT on the @a param; this is correct:

EXEC @rc = rjmTest6 @a OUTPUT
0
 
Scott PletcherSenior DBACommented:
You are setting @a = to the return code from the proc (which is 0).  Try this instead:

declare @a decimal(5,1)
declare @rc int

exec      @rc = rjmTest6 @a
print      @a

0
 
Maciej PileckiDatabase ArchitectCommented:
It should rather be:

declare @a decimal(5,1)
declare @rc int

exec      @rc = rjmTest6 @a OUTPUT
print      @a
0
 
scollegeAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.