August 5, 2010 at 9:00 am
Any idea why I get the "datediff function resulted in an overflow... error on one instance of SQL Server 2008 and not the other.
Instance A - operational db
Instance B - reporting db (transactional replication from 'A')
When I use the operation data store to reference a particular table I do not get the error. When I point the query to use the reporting copy of that table I then get the overflow error.
ABS(CONVERT(BIGINT,DateDiff(SS, s.dteAssignEndTS, c.dteFirstAssigned)))
Any help is greatly appreciated.
August 5, 2010 at 9:05 am
What are the data types of the two input columns in your datediff?
August 5, 2010 at 9:09 am
the error is related to the actual data being tested/datediffed. one instance has data that is out of range.
when you use datediff with seconds, there can only be something like a 67 year gap; after that the #seconds is greater than an int.
switch to datediff(minute and you'll fix the issue...if you are datediffing something that is 90 years, you don't need the # seconds difference anyway.
select DateDiff(SS,getdate(),'1900-01-01')
Msg 535, Level 16, State 0, Line 1
Difference of two datetime columns caused overflow at runtime.
do this instead: get minutes, multiply by 60 for seconds.
ABS(CONVERT(BIGINT,DateDiff(minute, s.dteAssignEndTS, c.dteFirstAssigned) * 60))
Lowell
August 5, 2010 at 9:34 am
The data type is datetime.
When I use ABS(CONVERT(BIGINT,DateDiff(mi, s.dteCrtTS, s.dteAssignEndTS)*60))
I get: Arithmetic overflow error converting expression to data type int.
August 5, 2010 at 9:42 am
You would need to convert the result of the datediff to a BIGINT before multiplying by 60...these must be long assignments!
E.g.:
ABS(CONVERT(BIGINT,DateDiff(mi, s.dteCrtTS, s.dteAssignEndTS))*60)
If both data types are datetime, then there must be different data in the two environments...
August 5, 2010 at 9:50 am
doh i should have tested that: wrapped the datediff evaluation with the convert first, sorry:
select ABS(CONVERT(BIGINT,(DateDiff(minute, getdate(), '1900-01-01'))) * 60),
ABS(CONVERT(BIGINT,(DateDiff(minute, s.dteCrtTS, s.dteAssignEndTS)))*60)
Lowell
August 5, 2010 at 9:50 am
Actually, you could have the same data, but you're for example using this function in a where clause along with other criteria and one execution plan is hitting a row that causes the overflow and one is not.
August 5, 2010 at 10:19 am
Thanks for catching that. I should've spotted it. This works.
ABS(CONVERT(BIGINT,(DateDiff(minute, s.dteCrtTS, s.dteAssignEndTS)))*60)
Wish I had time to dig into what differences are causing this.
Thanks Guys!
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy