How to Make Leading Wildcard Searches Fast


99.9% of you are never gonna need this.

But let’s say you need to run queries with leading (not trailing) wildcards, like this search for all the different national versions of the Encabulator, each of which has different prefixes depending on which government it’s being sold to:

SELECT * FROM dbo.Parts WHERE PartNumber LIKE ‘%8359’;

We’ll simulate it with a last name search in Stack Overflow Users table – granted, you would never store names in a single column, but let’s pretend we’re doing that for the sake of this post:

SELECT * FROM dbo.Users WHERE DisplayName LIKE ‘%Ozar’;

Even