I am writing a SQL query to return matching items based on a set of criteria, one of which is to check todays date against a date range - stored as two seperate columns 'DateFrom' and 'DateTo'
My Query is as follows:
SELECT
A.*
FROM
A
LEFT OUTER JOIN
B ON A.AlertID = B.AlertID
WHERE
A.AlertTypeID > 1 AND A.Active = 1 AND
(B.Complete IS NULL OR B.Complete < 1) AND
(A.DateFrom IS NULL OR
((CONVERT(datetime, A.DateFrom, 103) <= CONVERT(datetime, GETDATE(), 103) AND
CONVERT(datetime, A.DateTo, 103) >= CONVERT(datetime, GETDATE(), 103))))
This works fine if DateFrom and DateTo are different, but the issue I have is that I have an entry which has the same value in each, and it should be returned, but it is not.
Please can anyone advise on this one. Thanks.