Solved

int overflow

Posted on 2001-08-23
2
693 Views
Last Modified: 2012-06-27
Hi folks,

i have a proxy server logging to MMSSQL table.  i want to summarise the traffic each day to total per IP address.  i use this stored proc:

CREATE PROCEDURE update_TrafficLog @day int = 0

AS

insert into TrafficLog
select clientIP, convert(smalldatetime,convert(char, logtime,101),101), sum(bytessent) as bytesDelivered, 'proxy', 'proxy', newid()
from mspSrvLog
where logtime < convert(smalldatetime,convert(char, dateadd(d, -@day, getdate()),101),101) and logtime >= convert(smalldatetime,convert(char, dateadd(d, -1-@day, getdate()),101),101)
group by clientIP, convert(smalldatetime,convert(char, logtime,101),101)

delete mspsrvlog where logtime < convert(smalldatetime,convert(char, dateadd(d, -1-@day, getdate()),101),101)
GO

the column 'bytessent' is type int

the destimation column for sum(bytessent) is type bigint.

but sometimes this happens when i run the storedproc above:

Server: Msg 8115, Level 16, State 2, Procedure update_TrafficLog, Line 5
Arithmetic overflow error converting expression to data type int.
The statement has been terminated.

(0 row(s) affected)

- i assume that this is caused by the statement sum(bytessent) evaluating to a value greater than max INT - which being 2,147,483,647 is only 2.15GB, and not unlikely that this much data would be delivered to one address in a given day....

so how can i evaluate the sum(bytessent) as bigint?

cheers!


0
Comment
Question by:meverest
[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 Comments
 
LVL 39

Accepted Solution

by:
appari earned 75 total points
ID: 6420633
try the following

insert into TrafficLog
select clientIP, convert(smalldatetime,convert(char, logtime,101),101), sum( convert(numeric,bytessent)) as bytesDelivered,
'proxy', 'proxy', newid()
from mspSrvLog
where logtime < convert(smalldatetime,convert(char, dateadd(d, -@day, getdate()),101),101) and logtime
>= convert(smalldatetime,convert(char, dateadd(d, -1-@day, getdate()),101),101)
group by clientIP, convert(smalldatetime,convert(char, logtime,101),101)

delete mspsrvlog where logtime < convert(smalldatetime,convert(char, dateadd(d, -1-@day, getdate()),101),101)
0
 
LVL 37

Author Comment

by:meverest
ID: 6420815
thanks for that.  the convert function did the trick - but i chose to convert to bigint....  is there some advantage for using numeric datatype?

regards.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 shrink a transaction log file down to a reasonable size.

726 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