Solved

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

Posted on 2014-09-26
7
93 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
Comment Utility
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 45

Expert Comment

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

Author Comment

by:sqldba2013
Comment Utility
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
Comment Utility
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]
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Counting Distinct values in two columns 3 13
separate column 24 19
SQL Help - 12 32
Params not declared?  T-SQL syntax question 3 17
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

763 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

6 Experts available now in Live!

Get 1:1 Help Now