[Running SQL Server 2008 SP3]
I have a query which results in the overflow of a smalldatetime
type. However, this should (in theory) never happen, due to the way I have the query structured - the logic should cause the truth value to be known long before the DATEADD()
is executed which causes the overflow.
Here is the relevant part of the WHERE clause:
TimeIn >= '1/8/1950' AND TimeIn < '1/9/1950' AND
DATEADD(week, DATEDIFF(week, '1/8/1950', '9/14/2014'), TimeIn) >= '9/14/2014'
This works great - except when TimeIn (a smalldatetime
) is >= 10/1/2014, then it will overflow the smalldatetime space. But why does DATEADD()
even get executed? if the date is 10/1/14, it should never be executed... but it is.