concept bitmask in category sql
appears as: bitmasks, bitmask

This is an excerpt from Manning's book SQL Server MVP Deep Dives.
The bitmask value for the column must be at least equal to the bitmask for the search string. Thus, we can constrain the search to the upper part of the index. This leads to the procedure shown in listing 7.
Listing 7. Search function using the bitmask
CREATE PROCEDURE bit_search_two @wild varchar(50) AS SET NOCOUNT ON DECLARE @bitmask bigint SELECT @bitmask = dbo.char_bitmask(@wild) SELECT person_id, first_name, last_name, birth_date, email FROM persons WHERE email_bitmask >= @bitmask AND CASE WHEN email_bitmask & @bitmask = @bitmask THEN patindex('%' + @wild + '%', email) ELSE 0 END > 0