在另一个查询中使用来自一个查询的数据时出现ColdFusion语法错误

时间:2013-06-10 14:13:23

标签: coldfusion syntax-error

我在下面有以下代码,该代码应该根据他们的停车许可证号码获取学生信息:

<cfparam name="Permit" default="">

<cfquery name="q_sample" datasource="cars_live">
  SELECT * FROM veh_rec WHERE UPPER(DECAL) LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(urldecode(UCase(Permit)))#">
</cfquery>

<cfif q_sample.recordcount eq 0> 
No Results found for <cfoutput>"#Permit#"</cfoutput> 
</cfif>

<cfquery name="s_sample" datasource="cars_live">
  SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>
</cfquery>

<cfoutput query="s_sample">
  <p>Name: #FULLNAME#<p>
</cfoutput>

<cfoutput query="q_sample" >
  <p>License Plate Number: #license# <br><br> Permit ID Number: #decal#<br><br> Student ID Number: #ID# <br><br> Academic years: #ACADYR#<br><br></p>
</cfoutput>

牌照,许可ID号等都可以正常工作,但是当我尝试使用#q_sample.ID#标签时,我收到语法错误。但是,当我查看chrome控制台窗口中的错误时,我可以看到它根据许可证号获取了正确的ID。不知道为什么会这样。有谁看到我做错了什么?

谢谢!

按要求:

错误:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator. 

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Error Executing Database Query.

A syntax error has occurred.

The error occurred in /d2/www/vhosts/joeyP.cfm: line 11
9 : 10 : <cfquery name="s_sample" datasource="cars_live">11 :   SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>12 : </cfquery>13 : 

VENDORERRORCODE   -201

SQLSTATE      42000

SQL    SELECT FULLNAME FROM id_rec WHERE ID = 371043>

DATASOURCE    cars_live

Resources:

Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.

Browser     Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36

Remote Address      10.200.168.210

Referrer    http://{redacted}/tests/yup.html

Date/Time   10-Jun-13 09:17 AM

Stack Trace
at cfjoeyP2ecfm876470777.runPage(/d2/www/vhosts/joeyP.cfm:11) at cfjoeyP2ecfm876470777.runPage(/d2/www/vhosts/joeyP.cfm:11) 
我测试的数字是371043

1 个答案:

答案 0 :(得分:4)

在此查询结束时,您有一个非常>。如果你把它拿出来它应该解决你的问题。

<cfquery name="s_sample" datasource="cars_live">
SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>
</cfquery>