LIKE를 삽입하고 coldfusion을 사용하여 쿼리에서 my 매개 변수 내에 와일드 카드를 사용하는 데 약간의 문제가 있습니다.cfqueryparam에서 와일드 카드 사용 - Coldfusion
을 -<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>
디버깅을 켜고 생성 된 쿼리를 복사 한 다음 쿼리 분석기에서 실행하는 것이 좋습니다. 나는 보통 나의 모든 실수를 그런 식으로 발견 할 수있다. –
그 구문이 작동해야합니다. 나는 MS SQL Server와 동일한 것을 사용한다. 목록 항목 중 하나가 비어있어 쿼리에 오류가 발생 했습니까? –
@ Miguel-F No. 코드 섹션 # 1에서 쿼리가 나타나지만 코드 섹션 # 2에서는 나타나지 않습니다. – Zac