I have discovered some strange behavior where a stored procedure is returning inaccurate results by a penny or two.
Here's the code (I didn't write it):
ALTER PROCEDURE [dbo].[TN_GetSimpleBalance]
@custID int,
@nBalance decimal (8,2) output
AS
declare @ArBalance as decimal (8,2)
declare @custStatusCode varchar (2)
declare @unbilledCallsAmount as decimal (8,2)
set @nBalance = 0
set @ArBalance = 0
set @custstatusCode = ''
set @unbilledCallsAmount = 0
SET NOCOUNT ON
select @unbilledCallsAmount = isnull(sum(callcharge+taxamount),0)
from call with (NOLOCK) where custid = @custID and callstatuscode in ('R', 'B')
--get AR balance
select @ArBalance = isnull(sum(amount),0)
from artran with (NOLOCK)
where custid = @custID AND POSTEDFLAG ='Y'
set @nBalance = @unbilledCallsAmount + @ArBalance
@nBalance
is showing zero, even though another app is telling me the customer has $.02. callcharge
and taxamount
are both money datatypes.
This is the first time I've encountered this condition, but I am moving some related code to production and have been "asked" to research this.
What's your take? Is there weirdness going between money and decimal datatypes? Anything else you think might explain this?