如何修复SWITCH函数中的语法错误

时间:2019-07-05 13:53:49

标签: sql ms-access

我正在尝试根据type_match表中两列2018_status2019_status的内容填充一个标记为status_report的列。

所有三列均为短文本。我不断收到“语法错误”。

UPDATE status_report AS per  
SET per.type_match = 
Switch(
   per.2018_status = 'No application found', 'No application for 2018',
   per.2019_status = 'No application found', 'NA',
   per.2018_status = per.2019_status, 'Yes',
   True, 'No'
)

该文档似乎非常简单,并且认为这是MS Access问题,因此他们往往非常挑剔。

2 个答案:

答案 0 :(得分:1)

Switch没什么问题,您只需要将方括号括起来的列名就可以了:

UPDATE status_report AS per  
SET per.type_match = 
Switch(
   per.[2018_status] = 'No application found', 'No application for 2018',
   per.[2019_status] = 'No application found', 'NA',
   per.[2018_status] = per.[2019_status], 'Yes',
   True, 'No'
)

答案 1 :(得分:0)

您可以使用1=1作为默认值:

UPDATE status_report AS per  
    SET per.type_match = Switch(per.2018_status = "No application found", "No application for 2018,
                                per.2019_status = "No application found", "NA",
                                per.2018_status = per.2019_status, "Yes",
                                1=1, "No"
                         );

MS Access传统上也对字符串使用双引号,因此我也对其进行了更改。