Solved

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

Posted on 2014-09-26
7
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 143

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 49

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 143

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

749 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