concept bitmask in category sql

appears as: bitmasks, bitmask
SQL Server MVP Deep Dives

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

You could add characters directly to the char_frequency table, and because the table has a char(2) column, you could add two-character sequences as well. But because the bitmask is at best a bigint value, you cannot have more than 63 different weights.