Search code examples
coldfusioncoldfusion-11

CF11 QoQ search for a square bracket character


In a ColdFusion 11 application, I have a query object that contains strings that include an opening square bracket character - [. I need to be able to do a query of queries (QoQ) search of that query object to find any records that include the [ character, but I can't seem to find a way to escape it.

The best suggestion I've found - LIKE '%[[]%' - returns no results.

This code returns an error message:

<cfquery name="temp" dbType="query">
 SELECT *
 FROM myQuery
 WHERE myField LIKE '%[%'
</cfquery>

This code also returns an error message:

<cfquery name="temp" dbType="query">
 SELECT *
 FROM myQuery
 WHERE myField LIKE '%\[%' ESCAPE '\'
</cfquery>

And this code returns no records at all, even though I know the character is there:

<cfquery name="temp" dbType="query">
 SELECT *
 FROM myQuery
 WHERE myField LIKE '%[[]%'
</cfquery>

Any suggestions would be greatly appreciated. Thanks.


Solution

  • You were close. Using the link that gfrobenius posted, you get this:

    <cfquery name="temp" dbType="query">
     SELECT *
     FROM myQuery
     WHERE myField LIKE '%[\[ ]%'
    </cfquery>