I want to create a filtered index on (Column1 = Column2) condition:
CREATE NONCLUSTERED INDEX [IX_Document_IsBalanced]
ON [ACC].[Document] ([DocumentID] ASC)
WHERE SumCredit = SumDebit
ON [PRIMARY]
GO
Error Message is :
Incorrect syntax near the keyword ‘with’
The docs are quite confusing on this matter, but you cannot really create an index filtered on this condition (since it cannot be used on filtering statistics).
The docs say:
without clearly defining “simple”, but in fact “simple” means “usable by the filtered statistics”. The two have the same limitations.
The statistics can only use equalities, ranges and in-lists agains constants. This means you can only use the following predicates:
and their variations (
BETWEENetc), possibly combined with anAND(not evenOR).