I’m newer to SQL and I’m playing around with some existing queries in my database in SSMS – something I’ve been coming across lately is this line:
WHERE DE.Modified >=@FromDate AND DE.Modified < DATEADD(DAY,1,@ToDate)
Where FromDate and ToDate are given parameters. What I’m wondering is why one might write the second line instead of:
AND DE.Modified <=@ToDate
Is it a best practice in SQL to only use the less than operator and test against a date + 1, or are these the exact same?
EDIT:
FromDate and ToDate are declared as DATETIME:
DECLARE @FromDate DATETIME
, @ToDate DATETIME
Advertisement
Answer
You would write this to handle any time component on Modified.
In your version, anything that happens during the day of @ToDate would be missed.