I feel like this deserves a good comment but I get the feeling that what I have is merely a distraction.
- Does this deserve a comment?
- If so, can this comment be improved?
Please note that I am working with a poorly normalized application.
(
/* Remove Time Portion From ActivityDate */
DateAdd(Day, DateDiff(Day, 0, Activity.ActivityDate), 0) Not Between
/* Remove Time Portion From @MinimumDate Or SQL Server Min DateTime */
DateAdd(Day, DateDiff(Day, 0, Coalesce(@MinimumDate, '1753-01-01')), 0) And
/* Remove Time Portion From @MaximumDate Or SQL Server Max DateTime */
DateAdd(Day, DateDiff(Day, 0, Coalesce(@MaximumDate, '9999-12-31')), 0)
)
I’d wrap the dateadd/datediff in a scalar udf with a self commenting name and then pass in
Activity.ActivityDateorCoalesce(@MinimumDate, '1753-01-01'))as parametersSo you’d have this:
You could also have a “date if null” parameter and deal with COALESCE in the udf if it’s common enough in the SQL code
Now it’s obvious…no?