ColdFusion, SQL and Invalid Parameter Binding

While working on a multi-option search function for a client, I kept encountering a ColdFusion error, ‘Invalid Parameter Binding’. ¬†After much googling, I had found no solution that worked for me. ¬†Then I noticed that I had coded my parameter as such:

WHERE 0 = 0 
<cfif isNumeric(oArgs.Item)>
AND o.OrderId LIKE '%<cfqueryparam value="#oArgs.Item#" cfsqltype="cf_sql_varchar" maxlength="100" />%'
<cfelse>
AND d.TransactionId LIKE '%<cfqueryparam value="#oArgs.Item#" cfsqltype="cf_sql_varchar" maxlength="100" />%'
</cfif>

Maybe a silly mistake, but the solution was profoundly simple, even if the error message was not very informative. Updating my code to remove the single quotes and include the % inside of the cfqueryparam tag was all that needed to be done.

WHERE 0 = 0 
<cfif isNumeric(oArgs.Item)>
AND o.OrderId LIKE <cfqueryparam value="%#oArgs.Item#%" cfsqltype="cf_sql_varchar" maxlength="100" />
<cfelse>
AND d.TransactionId LIKE <cfqueryparam value="%#oArgs.Item#%" cfsqltype="cf_sql_varchar" maxlength="100" />
</cfif>

Made the change and everything started working as expected.