I am looking to retrieve all records which myDate is between the startDate and ‘endDate’, but do not return records with exactly the same date. I am using MS SQL 2005.
I have tried:
Select *
From myDatabase
Where empId = 145
and myDate between startDate and endDate
But if myDate was ’11/16/2011′ the above query would return records which have a startDate and endDate = ’11/16/2011′ as well. This isn’t what I want. I do not want records which have a startDate and endDate = myDate
So I tried:
Select *
From myDatabase
Where empId = 145
and myDate between startDate and endDate
and (myDate <> startDate AND myDate <> endDate)
Will this work for all cases?
a1ex07 is right in that this will work
myDate > startDate AND myDate < endDateIf you insist on using
BETWEENthen this will work alsomydate BETWEEN startDate + INTERVAL 1 DAY AND endDate - INTERVAL 1 DAYEdit: Just saw the tags for SQL Server not MySQL so the above is for MySQL, the SQL Server equivalent is
myDate BETWEEN DATEADD(DAY, 1, startDate) AND DATEADD(DAY, -1, endDate)