SQL: datetime2 overflow in WHERE, but not in SELECT

298
March 10, 2017, at 01:59 AM

I've seen plenty of threads about datetime2 overflows when hitting the minimum date, but I don't have that in my data. Additionally, the DATEADD works fine in the SELECT statement, but not in the WHERE statement. Here's what I'm trying to do:

SELECT DATEADD(hour, -8, MyDate) as 'PST Date'
FROM [dbo].[MyTable]
WHERE DATEADD(hour, -8, MyDate) between '2017-01-01' and '2017-02-01'

Which resolves to:

Adding a value to a 'datetime2' column caused an overflow.

This query works just fine if I take out the DATEADD from the WHERE statement, but then I'm getting an 8-hour shift in my results. Any idea why this is happening or what I can do to make the WHERE work properly? Thanks!

READ ALSO
AND Condition (from array)

AND Condition (from array)

To populate dropdown from database I use a simply query like this

214
MySQL: Pivot-like query result

MySQL: Pivot-like query result

Given the following query, which produces a list of students and the cohorts to which they are assigned:

234
Why is this OracleCommand Select Count returning the incorrect value

Why is this OracleCommand Select Count returning the incorrect value

I've tried this code targeting two different Oracle Databases both returning different resultsBoth times, the first table returned the correct value (correct by me using this command in SQL Developer)

270
mysqli_query expects at least 2 parameters

mysqli_query expects at least 2 parameters

This mysqli_query command results in the error below

527