在使用coldfusion的查询中插入LIKE并在我的参数中使用通配符时遇到了一些麻烦。这是目前有效的:
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ListGetAt(selectList2,i)#" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>
我的目标是在可以输入参数的地方获取代码(但它目前不起作用 - 错误读取无法执行查询)
<cfquery name="sample" datasource="database"><!---Take the query here--->
SELECT * <!---select all--->
FROM table <!---from the table "table"
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i">
#ListGetAt(selectList1, i)# LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#ListGetAt(selectList2,i)#%" /> <!---
search column name = query parameter
using the same index in both lists
(selectList1) (selectList2) --->
<cfif i neq listLen(selectList1)>AND</cfif> <!---append an "AND" if we are on any but
the very last element of the list (in that
case we don't need an "AND"--->
</cfloop>
</cfquery>