Not sure this is ever going to go very fast. Also, using the function that way, while it is an inline table-valued function, the problem is that it's used in a way that I'm not sure is really going to work very well. You also are performing a REPLACE function on long string data, so that's not helping either. You might be able to use FULL TEXT INDEXING, because your search is a CONTAINS kind of search, and it would have to be on the smaller table. I don't know enough about FTI to help much, so Google will be your best friend in that regard.