SQL 为什么在运行 MS Access 查询时会收到“输入参数值”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4232639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:21:35  来源:igfitidea点击:

Why am I getting “Enter Parameter Value” when running my MS Access query?

sqlms-accessselectsubquery

提问by Teiv

SELECT ID, 
       Name, 
       (SELECT CityName 
        FROM City 
        WHERE Employee.CityID = City.CityID) AS [City Name] 
FROM Employee 
WHERE [City Name] = "New York"

I'm about selecting all employees who come New York but whenever I run the query, I always get a “Enter Parameter Value” box. How can I fix this?

我打算选择所有来到纽约的员工,但每当我运行查询时,我总是得到一个“输入参数值”框。我怎样才能解决这个问题?

回答by Remi Despres-Smyth

This is because Access does not allow you to use field aliases in the query - it does not recognize [City Name] as a valid field name. Aliases are only used as field names in the result set. Rather, you need to use the entire expression.

这是因为 Access 不允许您在查询中使用字段别名 - 它不会将 [City Name] 识别为有效的字段名称。别名仅用作结果集中的字段名称。相反,您需要使用整个表达式。

As such, this query would probably be more easily defined in Access as:

因此,这个查询可能更容易在 Access 中定义为:

SELECT ID, 
       Name, 
       CityName AS [City Name]
FROM Employee INNER JOIN City
    ON Employee.CityID=City.CityID
WHERE CityName = "New York"

Also, 'Name' is a reserved word - using it as a field name is not suggested.

此外,“名称”是保留字 - 不建议将其用作字段名称。

回答by Jacob Church

Another thing to check is on the Home tab if you have any manual sorts or filters active on the query results. There is a button on that tab to remove sorting that you wont find on the dropdown menu for the field.

另一件要检查的事情是在“主页”选项卡上,是否在查询结果上有任何手动排序或过滤器处于活动状态。该选项卡上有一个按钮可以删除您在该字段的下拉菜单中找不到的排序。

回答by Mohamad Alhamoud

try single quotes instead of double quotes.

尝试单引号而不是双引号。