1

我需要使用 Access 2007 和 ColdFusion 8 在一个简单的选择语句中组合 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
4

1 回答 1

3

Majors在和之间添加的空格周围使用单引号而不是双引号GradeLevel

SELECT Majors & ' ' & GradeLevel 
FROM Programs
WHERE Categories = 'Language'
ORDER BY Majors

如果您的下一个问题是如何为该字段表达式设置别名,则当您使用现有字段名称作为别名时,Access db 引擎可能会反对。通过选择与任何字段名称都不匹配的别名来避免该问题。

SELECT Majors & ' ' & GradeLevel AS Majors_GradeLevel
于 2013-10-07T18:28:01.443 回答