I have a table Com_Main
which contains column CompanyName nvarchar(250)
. It has average length of 19, max length = 250.
To improve performance I want to add a computed column left20_CompanyName
which holds the first 20 characters of CompanyName
:
alter table Com_main
add left20_CompanyName as LEFT(CompanyName, 20) PERSISTED
Then I create Index on this column:
create index ix_com_main_left20CompanyName
on Com_main (LEFT20_CompanyName)
So when I use
select CompanyName from Com_Main
where LEFT20_CompanyName LIKE '122%'
it uses this nonclustered index, but when the query is like:
select CompanyName from Com_Main
where CompanyName LIKE '122%'
It uses full table scan, and don't use this index.
So the question:
Is it possible to make SQL Server use this index on computable column in last query?