我需要使用Access 2007和ColdFusion 8在一个简单的select语句中组合来自2列的值。当我在Access中运行我的查询时,我得到的结果没有问题,但是当我将查询放在ColdFusion中时它赢了'运行:
<cfquery name="Maj" datasource="#application.dsn#">
SELECT Majors & " " & GradeLevel
FROM Programs
WHERE Categories = 'Language'
ORDER BY Majors
</cfquery>
它会产生以下错误:
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
The error occurred in C:\Inetpub\wwwroot\test.cfm: line 4
2 :
3 :
4 : <cfquery name="Maj" datasource="#application.dsn#">
5 : SELECT Majors & " " & GradeLevel
6 : FROM Programs
答案 0 :(得分:3)
在Majors
和GradeLevel
之间添加的空格周围使用单引号而不是双引号。
SELECT Majors & ' ' & GradeLevel
FROM Programs
WHERE Categories = 'Language'
ORDER BY Majors
如果您的下一个问题是如何为该字段表达式设置别名,则当您使用现有字段名称作为别名时,Access数据库引擎可能会出现对象。通过选择与任何字段名称都不匹配的别名来避免这个问题。
SELECT Majors & ' ' & GradeLevel AS Majors_GradeLevel