Performing Pattern Matching

Use the SQL LIKE operator and SQL wildcard strings in a SQL WHERE clause when you want to compare a value against a character string field so that the query returns database information based on commonalities. This is known as pattern matching and often used to query databases.

For example, to return data for employees whose last name starts with AL and ends with anything, you would build a query that looks like this:

<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
    SELECT FirstName, LastName,
    StartDate, Salary, Contract
    FROM    Employees
    WHERE   LastName LIKE 'AL%'
</CFQUERY>
Note By default, SQL is not case-sensitive.