SQL语法错误缺少运算符MS访问

时间:2015-06-10 15:28:30

标签: sql ms-access

我正在尝试运行一个查询,如果另一个表中的字段等于test,它将更新一个表中的字段。这是代码:

on(t.pinFilterButton.dropDownContainer, 'close', function (e) {
    e.stopPropogation();
})

但是,当我运行它时,我总是收到UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 ON t1.Field1 = t2.F_Name SET t1.Field4 = (CASE WHEN t2.PlayField = 'test' THEN 'test' ELSE 'No test' END); 。不确定我做错了什么......

3 个答案:

答案 0 :(得分:2)

因为你只想了解这个问题。你的SQL:

UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 
ON t1.Field1 = t2.F_Name
SET t1.Field4 =
    (CASE 
        WHEN t2.PlayField = 'test' THEN 'test' 
        ELSE 'No test' 
    END);

MS Access不支持CASE语句。它看起来像SQL Server,而不是MS Access。

你可以尝试:

 SET t1.Field4 =
IIf([t2].[playfield]='test','test','No test');

这基本上说:设置t1.Field =如果t2.PlayField = 'Test',我们将使用'test'一词,如果不是,我们将使用'No Test'。

答案 1 :(得分:2)

Access SQL不支持

CASE ... WHEN。请改用IIf

UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 
ON t1.Field1 = t2.F_Name
SET t1.Field4 =
    IIf(t2.PlayField = 'test', 'test', 'No test');

答案 2 :(得分:0)

如果问题与MS Access数据库引擎有关...

看看这里:MS Access 2003: Update Query that updates values in one table with values from another table

您的查询应如下所示:

UPDATE TableName
SET TableName.Field1 = (SELECT AnotherTable.Field2
                        FROM AnotherTable
                       WHERE AnotherTable.Field3 = TableName.Field2)
WHERE (<<condition>>);

CASE WHEN ... END语句只能在VBA中使用。要在查询中实现诸如条件结果,请使用IIF函数。

请参阅:IIF function