I have a table with a dateTime column on which I want to put a filtered index. This index will get rebuilt each week. Each time it’s rebuilt, I want it to include rows two days old and newer, based on this column. Can I create such a filtered index? I’ve tried various approaches and I get syntax errors.
For example, the following Where clause on the index creation did not work:
WHERE (ReadTime > DateAdd(dd,-2,GetDate()))
You can’t do this by referencing
getdate()directly. You would need dynamic SQL.The
CREATE INDEXgrammar only allows comparisons against a constant.