Meneghino
Meneghino

Reputation: 1021

Unique filtered index with multiple conditions in SQL Server

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

Upvotes: 7

Views: 8081

Answers (1)

Vivek
Vivek

Reputation: 124

Use the following syntax:

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

Upvotes: 10

Related Questions