Solved

Arithmetic Overflow SQL

Posted on 2014-09-14
1
180 Views
Last Modified: 2014-09-14
I have a stored procedure which used to work perfectly but has started to error with
"Msg 8115, Level 16, State 8, Procedure stp_UpdateTempStops, Line 9
Arithmetic overflow error converting int to data type numeric"

INSERT INTO temptbl_Stops (StartDate, StopDate, StopTime, DownTimeCode)
SELECT     TOP (100) PERCENT StartDate, StopDate, Avg(cast(DATEDIFF(s, StartDate, StopDate)/60 AS DECIMAL(4,2))) AS StopTime, DowntimeCode
FROM         dbo.tbl_MachineData
GROUP BY StartDate, StopDate, DowntimeCode
HAVING       Avg(cast(DATEDIFF(s, StartDate, StopDate)/60 AS decimal(4,2))) IS NOT NULL and DowntimeCode IS NULL and StopDate IS NOT NULL
ORDER BY StartDate

All help most welocme.....I am using SQL2012 Express
0
Comment
Question by:SweetingA
1 Comment
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 40322239
The difference between these two dates (StartDate, StopDate) when divided by 60 seconds (i.e. converted to minutes) is greater than 99.99 minutes. You need to alter table temptbl_Stops to allow more ranges for StopTime column. E.g. if you wish to have the StopTime to be in 999.99 range use this syntax:
ALTER TABLE temptbl_Stops ALTER COLUMN StopTime DECIMAL(5,2) NULL
GO
INSERT INTO temptbl_Stops (StartDate, StopDate, StopTime, DownTimeCode)
SELECT     TOP (100) PERCENT StartDate, StopDate, Avg(cast(DATEDIFF(s, StartDate, StopDate)/60 AS DECIMAL(5,2))) AS StopTime, DowntimeCode
FROM         dbo.tbl_MachineData
GROUP BY StartDate, StopDate, DowntimeCode
HAVING       Avg(cast(DATEDIFF(s, StartDate, StopDate)/60 AS decimal(5,2))) IS NOT NULL and DowntimeCode IS NULL and StopDate IS NOT NULL
ORDER BY StartDate

Open in new window

If it is still not enough ALTER to a different type, i.e. DECIMAL(6,2)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question