I would pack the dateadd / dated into a scalar udf with a self-commenting name, and then pass in Activity.ActivityDateor Coalesce(@MinimumDate, '1753-01-01'))as parameters
So, you will have the following:
(
dbo.ufnGetDateOnly (Activity.ActivityDate) NOT BETWEEN
dbo.ufnGetDateOnly (COALESCE(@MinimumDate, '1753-01-01')) AND
dbo.ufnGetDateOnly (COALESCE(@MaximumDate, '9999-12-31'))
)
You can also have a "date if null" parameter and work with COALESCE in udf if it's common enough in SQL code
(
dbo.ufnGetDateOnly (Activity.ActivityDate, DEFAULT) NOT BETWEEN
dbo.ufnGetDateOnly (@MinimumDate, '1753-01-01') AND
dbo.ufnGetDateOnly (@MaximumDate, '9999-12-31')
)
Now this is obvious ... no?
source
share