I am trying to select MTR values that are between the values of 0 and 4. What am I doing wrong?
SELECT
DATEDIFF(M, TheDate, TheOtherDate) AS MTR FROM MyTable
WHERE MyID = 2074163
AND MTR >= 0 OR MTR <= 4
Returns results that contain values inside and outside of the bounds of MTR being between 1 and 4. (from -3 to 75)
Alternately
SELECT
DATEDIFF(M, TheDate, TheOtherDate) AS MTR FROM MyTable
WHERE MyID = 2074163
and MTR BETWEEN 0 AND 4
Is also returning results that are 0, -2, -3, and -4 - but nothing higher than 0 and less than 4 (except for the entries that are 0)
MTRcolumn in the table. – ypercube Sep 11 '12 at 13:32TheDatevalue is not greater thanTheOtherDateif you expect to receive non-negative results. I.e.,DATEDIFF(M, '2012-02-20', '2012-05-15')evaluates to3, but if you swap the dates, you'll get-3. – Andriy M Sep 11 '12 at 16:44