我有一个问题:
<cfif topic NEQ "">
<cfquery name="queryTopicName" datasource="#ODBC#">
select topic as topicName from ltbTopics where topicId in (#topic#)
</cfquery>
<cfset selectedRiskCategories = ValueList(queryTopicName.topicName)>
</cfif>
这里“#topic#”包含一个第一个值为空的列表,所以它就像,51,52,等所以它给出了一个错误:
“','
附近的语法不正确
。
第33行出现错误“,任何人都可以帮我解决这个问题吗?
答案 0 :(得分:1)
有很多方法可以做到这一点。但是一个简单的黑客就是将列表转换为数组,然后返回列表。
<cfif topic NEQ "">
<cfset arrayTopic = ListToArray(topic)>
<cfset topic = ArrayToList(arrayTopic)>
<!---you may need some more validations as it is possible that original list only has commas in it--->
<cfquery name="queryTopicName" datasource="#ODBC#">
select topic as topicName from ltbTopics where topicId in (#topic#)
</cfquery>
<cfset selectedRiskCategories = ValueList(queryTopicName.topicName)>
</cfif>
答案 1 :(得分:1)
谢谢您的答案,最终查询对我有用 完美是:
<!--- Query to extract selected risk category filters --->
<cfif topic NEQ "">
<cfset arrayTopic = ListToArray(topic)>
<cfset topic = ArrayToList(arrayTopic)>
<cfquery name="queryTopicName" datasource="#ODBC#">
select
topic as topicName
from
ltbTopics
where
topicId in
(
<cfqueryparam
value = "#topic#"
cfsqltype= "CF_SQL_INTEGER"
list = "true"
/>)
</cfquery>
<cfset selectedRiskCategories = ValueList(queryTopicName.topicName)>
</cfif>
Once again thanks for your help, I really appreciate it.