CF quickie: cfqueryparam with SQL’s LIKE operator

If you are using cfqueryparam to build a SQL statement from a search form and need to use the SQL’s LIKE operator here is how it’s done in the most basic way:

<cfquery name="qData" datasource="myDsn">
SELECT DISTINCT last_name
FROM person
WHERE last_name LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.last_name#%">
ORDER BY last_name
</cfquery>

The magic is all in the % sign at the end of the cfqueryparam value attribute.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.