Running Small Business Server 2003 premium.
Im having a terrible time trying to determine why I keep getting
Arithmetic overflow error converting expression to data type money.
Question 1.)
I get the error:
Server: Msg 8115, Level 16, State 1, Procedure pCalcTwiggs_250, Line 172
Arithmetic overflow error converting expression to data type money.
Procedure pCalcTwiggs_250 is a compiled stored procedure. How do you find line 172? Do you right click on the stored procedure in EM and view properties? When I do this, it shows me this line:
SET @currLastTwiggsVolumeTEMP = @currLastTwiggsVolumeTEMP / @currTwiggsDaysDenom
At the bottom right of the window I see 72, 172/246.
Question 2.) What does the 72 mean?
Question 3.)
If line 172 is the one above the problem does not occur there. The error happens only when @currLastTwiggsVolumeTEMP
is written to a table (see >> here below).
This is so incredibly frustrating. When I remove @currLastTwiggsVolumeTEMP from the INSERT statement then everything works well, no errors. When I add it back then the errors occur. The line containing the INSERT statement is NOT line 172.
How do I troubleshoot this? I have to get this project done.
Here is the relevant code
== Twiggs Calculation:
-- == Assign integers to money to allow fractions
SET @currTwiggsDaysDiff = @intTwiggsDays - 1
SET @currTwiggsDaysDenom = @currTwiggsDaysDiff / @intTwiggsDays
SET @currAdvDeclineYest = @currAdvDeclineYest / @currTwiggsDaysDenom
SET @currLastTwiggsVolumeTEMP = CAST(@intLastTwiggsVolume AS MONEY)
Line 172> SET @currLastTwiggsVolumeTEMP = @currLastTwiggsVolumeTEMP / @currTwiggsDaysDenom
SET @intLastTwiggsVolume = CAST(@currLastTwiggsVolume
TEMP AS BIGINT)
-- == Cannot use next line because int divided by money produces arithmetic overflow
-- SET @intLastTwiggsVolume = @intLastTwiggsVolume / @currTwiggsDaysDenom
-- * * * * * * * * * * * * * * * *
SET @currAdvDecline = @currAdvDeclineYest + @currAdvDecline
SET @intCurrentTwiggsVolume = @intLastTwiggsVolume + @intVolumeToday
SET @currTwiggsCalc_250 = @currAdvDecline / CAST(@intCurrentTwiggsVolu
me AS MONEY)
-- orig SET @currTwiggsCalc_250 = @currAdvDecline / @intCurrentTwiggsVolume
IF (@@ERROR <> 0)
BEGIN
SET @strComments = 'Label 3100: After Calc Twiggs - division by zero?'
SET @intError = @@ERROR
SET @strComments = 'Error ' +
CAST(@intError AS CHAR(9))
+ ' occurred'
EXEC ptblErrorLog
@strUserID = @strUserID ,
@strFunctionID = @strFunctionID ,
@intPatternID = @intPatternID ,
@strSymbol = @strSymbol ,
@strComments = @strComments ,
@strCallingProgram = 'pCalcTwiggs_250'
END
-- * * * * * * * * * * * T E s t
SET @strTwiggsCalcTEMP = CAST(@currTwiggsCalc_250 AS CHAR(1000)) -- temp
SET @strCurrentTwiggsVolumeTEM
P = CAST(@intCurrentTwiggsVolu
me as CHAR)
-- * * * * * * * * * * * * *
/*
-- No @intCurrentTwiggsVolume
INSERT INTO dbo.tblTestWrite
(Symbol, EntryDate, Volume)
VALUES
(@strSymbol, @datTodaysDate, @intCurrentTwiggsVolume)
*/
SET @currLastTwiggsVolumeTEMP = CONVERT(MONEY, @intCurrentTwiggsVolume)
INSERT INTO dbo.tblTwiggsMF
(Symbol, EntryDate, Volume)
VALUES
>>here (@strSymbol, @datTodaysDate, @currLastTwiggsVolumeTEMP)
================== Below is table tblTwiggsMF ==========================
==
DROP PROCEDURE pCreate_tblTwiggsMF
go
CREATE PROCEDURE pCreate_tblTwiggsMF
AS
IF EXISTS
(
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'tblTwiggsMF'
)
DROP TABLE dbo.tblTwiggsMF
CREATE TABLE dbo.tblTwiggsMF
(
RecID bigint IDENTITY NOT NULL,
Symbol varchar(7) NOT NULL
FOREIGN KEY REFERENCES dbo.tblSecurity(Symbol),
CONSTRAINT tblTwiggsMF_PK PRIMARY KEY
(RecID, Symbol, EntryDate),
EntryDate smalldatetime NOT NULL DEFAULT GETDATE(),
Volume money NOT NULL DEFAULT 0,
-- Volume bigint NOT NULL DEFAULT 0,
Active tinyint NOT NULL DEFAULT 1
)
Return
Start Free Trial