Coldfusion 从值列表中删除null
我有一个问题:Coldfusion 从值列表中删除null,coldfusion,Coldfusion,我有一个问题: <cfif topic NEQ ""> <cfquery name="queryTopicName" datasource="#ODBC#"> select topic as topicName from ltbTopics where topicId in (#topic#) </cfquery> <cfset selectedRiskCategories = ValueList(queryTop
<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>
在这里,主题包含一个列表,其第一个值为空,因此它像、、51、52等出现,因此它给出一个错误,如下所示:
“,”附近的语法不正确
。错误发生在第33行,有谁能帮我解决这个问题吗?有很多方法可以解决这个问题。但是一个简单的方法是将列表转换为数组,然后再返回列表
<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>
有很多方法可以做到这一点,但一个简单的方法是将列表转换为数组,然后返回列表
<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>
谢谢你对我的最后一个问题的回答 这完全是:
<!--- 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.
谢谢你对我的最后一个问题的回答 这完全是:
<!--- 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.
您好,谢谢您发布建议,您能详细说明如何在上面的代码中实现它吗?在查询中使用cfqueryparam以防止sql注入并避免执行计划重新生成。有没有办法使用query param?你能推荐一下吗?提前谢谢。嘿,我正在尝试使用cf查询参数方法,你能告诉我哪里出了问题吗?从ltbTopics中选择topic作为topicName,其中topicId位于Hi感谢您发布建议,您能否详细说明如何在上述代码中实现它?在查询中使用cfqueryparam以防止sql注入并避免执行计划重新生成。有没有办法使用query param?你能推荐一下吗?提前谢谢。嘿,我正在尝试使用cf查询参数方法,你能告诉我哪里出了问题吗?从ltbTopics中选择topic作为topicName,其中topicId在I中建议循环和测试整数,或使用justNumericList UDF首选。如果topic值是表单或URL参数,这一点尤其重要。注意非整数数值科学记数法、长、十进制、数字后跟空格等。我建议循环和测试整数或使用justNumericList自定义项首选。如果主题值是表单或URL参数,这一点尤其重要。注意非整数值,科学记数法、长、十进制、数字后跟空格等。您提到的是空值。此列表是否来自另一个查询?如果是,并且您仅使用该查询检索此查询的值,那么您可以将其作为topicName从ltbTopics中包含在另一个select topic中,其中topicId从某个_other_表中选择topic,其中something=something _else您提到的是null。此列表是否来自另一个查询?如果是,并且您仅使用该查询检索此查询的值,那么您可以将其作为topicName从ltbTopics中包含在其他选择主题中,其中topicId从some_other_表中选择主题,其中something=something_other