Suppose I have a table
MyTab (ID int, MyNo varchar(50),.....)
There is a index on the MyNo
column.
Then I have following SQL query:
declare @Nos varchar(100000)
set @Nos = ',001,002,003,004,'
Select *
from MyTab
Where CHARINDEX(',' + MyNo + ', @Nos) > 0
It is fine when the string @Nos
is short. But if @Nos
is larger, say length is 10000, the query performance is pretty bad.
How to improve the performance for this case? Or better solution to replace the query?