Maybe I'm making an obvious mistake but can anyone explain what's going on here? I was running a query where the table's field is datetime and the query I was running was something like
SELECT *
FROM Table
WHERE DateTimeColumn <= '20170714'
and I noticed the output excluded the records where DateTimeColumn
is '20170714'
they finished at '20170713'
Below I was expecting all 3 IIF to fall into true.
DECLARE @d1 DATE = '20170714'
SELECT IIF(GETDATE() <= @d1, 'GETDATE() Less than or equal to @d1', 'GETDATE() **NOT** Less than or equal to @d1')
DECLARE @d2 DATE = '20170714 11:59:59'
SELECT IIF(GETDATE() <= @d2, 'GETDATE() Less than or equal to @d2', 'GETDATE() **NOT** Less than or equal to @d2')
DECLARE @tomorrow DATE = '20170715'
SELECT IIF(GETDATE() <= @tomorrow, 'GETDATE() Less than or equal to @tomorrow', 'GETDATE() **NOT** Less than or equal to @tomorrow')