我在Microsoft Access 2007中工作的数据库中遇到了CASE语句的某种问题。 现在,这是我的问题:
SELECT Email, CASE State
WHEN "NC" THEN "North Carolina"
ELSE "Not Known"
END AS "Origin"
FROM Customers
所有数据对象都有正确的名称,我无法说明为什么查询不会在我的生命中运行。有帮助吗?感谢。
答案 0 :(得分:3)
访问权限不支持CASE
。对于该示例,您可以使用IIF
SELECT Email,
IIF(State = "NC", "North Carolina", "Not Known") AS "Origin"
FROM Customers
如果这是一个减少的示例,您可能需要一个表映射外部联接的状态代码和名称的表。
或者您可以使用SWITCH
SELECT
Switch(
State = "NC", "North Carolina",
State = "SC", "South Carolina"
True,"Not Known"
) AS Origin
FROM Customers;
答案 1 :(得分:0)
您可以使用以下内容执行此操作:
SELECT Email, Iif(State = "NC", "North Carolina", "Not Known") AS "Origin" FROM Customers
您的CASE语句对应于MSSQL语法,该语句被用作Access应用程序的BE数据库。但是Access不支持它。