How to get all index columns including filtered columns?
if object_id('dbo.tTestIndex') is not null
drop table dbo.tTestIndex;
create table dbo.tTestIndex (a int, b int, c int);
create index X_tTestIndex on dbo.tTestIndex (a) include (b) where c > 0;
select i.name, i.filter_definition, c.name, ic.is_included_column
from sys.indexes i
inner join sys.index_columns ic on i.object_id = ic.object_id and i.index_id = ic.index_id
left join sys.columns c on ic.object_id = c.object_id and ic.column_id = c.column_id
where i.object_id = object_id('dbo.tTestIndex');
if object_id('dbo.tTestIndex') is not null
drop table dbo.tTestIndex;
This example gives two rows instead of three.
index_name | filter_definition | column_name | is_included_column
-------------+-------------------+-------------+-------------------
X_tTestIndex | ([c]>(0)) | a | 0
X_tTestIndex | ([c]>(0)) | b | 1
You can use the catalog view sys.sql_expression_dependencies to find out the columns on which your filter relies:
You can then just
UNIONthis to your original query to get all the columns.