Improving performance of SUBSTRING queries

Sometimes I see queries that use SUBSTRING in the query predicate.  This makes the query non-sargable (i.e. indexes aren’t usable). Example query: SELECT * FROM CustomerAccount WHERE SUBSTRING(AccountNbr, 0, CHARINDEX(‘-‘, AccountNbr)) = ‘999999’ This query is searching for an account number where everything up to the hyphen is stripped out.  Applying the SUBSTRING function causes […]

Read More