Unique filtered index with multiple conditions in SQL Server

6.9k views Asked by At

Is it possible to create a filtered index in SQL Server with multiple conditions?

Here is what I am trying to do, but gives 'incorrect syntax' error:

CREATE UNIQUE NONCLUSTERED INDEX IX_TestTable  
ON TestTable(MyIntColumn)  
WHERE MyIntColumn is not null OR MyIntColumn<>0
1

There are 1 answers

0
Vivek On BEST ANSWER

Use the following syntax:

CREATE UNIQUE NONCLUSTERED INDEX IX_TestTable  
ON TestTable(MyIntColumn)  
WHERE ISNULL(MyIntColumn,0) <> 0