Solved

SQL query error (Arithmetic overflow error converting expression to data type int)

Posted on 2014-09-26
7
107 Views
Last Modified: 2016-05-20
Hi Experts,

I am facing below error while running attached stored procedure. Please advise how to fix below error.

Error:
Msg 8115, Level 16, State 2, Procedure usp_Main_GetCPUHistory, Line 8
Arithmetic overflow error converting expression to data type int.

Stored procedure:
create procedure MS_PerfDashboard.usp_Main_GetCPUHistory
as
begin
	declare @ts_now bigint
	select @ts_now = cpu_ticks / convert(float, ms_ticks) from sys.dm_os_sys_info
	
	select top 15 record_id,
		dateadd(ms, -1 * (@ts_now - [timestamp]), GetDate()) as EventTime, 
		SQLProcessUtilization,
		SystemIdle,
		100 - SystemIdle - SQLProcessUtilization as OtherProcessUtilization
	from (
		select 
			record.value('(./Record/@id)[1]', 'int') as record_id,
			record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') as SystemIdle,
			record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') as SQLProcessUtilization,
			timestamp
		from (
			select timestamp, convert(xml, record) as record 
			from sys.dm_os_ring_buffers 
			where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
			and record like '%<SystemHealth>%') as x
		) as y 
	order by record_id desc
end

Open in new window

0
Comment
Question by:sqldba2013
  • 2
  • 2
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40345740
the issue is very likely the expression:
 (@ts_now - [timestamp])

or this one:
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int')

either of the 2 is not a INT as value, please double-check your data
0
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 40345787
It's running OK for me.
How are you calling the SP?
0
 

Author Comment

by:sqldba2013
ID: 40345817
Still I am not able to find root cause of error.

I am executing SP through CMS (Central management servers). In CMS I've registered three SQL servers and I am getting output for two servers and I am not able to fetch data for remaining one server.

I am using below command to fetch data from CMS:
use msdb;
Exec MS_PerfDashboard.usp_Main_GetCPUHistory

Svr 1: it returns 15 rows without error
Svr 2: it returns 15 rows without error
Svr 3: No records and Got above error

Sample data of Svr 1 and Svr 2:
Server Name          record_id      EventTime                               SQLProcessUtilization      SystemIdle      OtherProcessUtilization
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Svr 1                 496               2014-09-27 00:29:20.633              0                                         77                             23
Svr 1                495               2014-09-27 00:28:20.630             0                                        75                             25
Svr 2              1584              2014-09-27 09:15:41.960            6                                        89                            5
Svr 2              1583              2014-09-27 09:14:41.873              6                                         90                                4
0
 

Assisted Solution

by:sqldba2013
sqldba2013 earned 0 total points
ID: 40345820
I found the solution using below URL.

http://celticcodingsolutions.com/Blog/post/2011/05/11/Microsoft-Performance-Dashboard-for-SQL-Server-2008-Issue-3.aspx

Now I am able to run SP qithout error.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40345882
which is doing exactly what I suggested:
>the issue is very likely the expression:  (@ts_now - [timestamp]) <

dividing by 1000 to get a smaller value...
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now