查询表达式中的另一个语法错误(缺少运算符)

时间:2014-12-23 17:36:10

标签: sql vba ms-access-2007

我需要一些帮助来开发我的SQL查询。我的目标是删除一个条目。我的情况是两张桌子了。我已经走到了这一步,但我似乎无法找到另一个错误

con.Execute "DELETE FROM Expenses INNER JOIN Agreements ON Agreements.AgreementsID = 
             Expenses.AgreementID AND INNER JOIN Audits 
             ON Audits.AuditID = Agreements.AuditID WHERE Audits.Share = True"

我正在使用access 2007而我的con变量是

con.Open _
"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" & _
"Dbq=" & Loc & ";"

1 个答案:

答案 0 :(得分:1)

试试这个,你在AND之前使用INNER JOIN,只删除它。

DELETE DISTINCTROW Expenses.* 
  FROM Expenses 
           INNER JOIN Agreements ON Agreements.AgreementsID = Expenses.AgreementID 
           INNER JOIN Audits ON Audits.AuditID = Agreements.AuditID 
  WHERE Audits.Share = True

[编辑查询]

  DELETE Expenses.* 
  FROM Expenses 
  WHERE Expenses.AgreementID IN (
                         SELECT Agreements.AgreementID FROM Agreements 
                         INNER JOIN Audits ON Audits.AuditID = Agreements.AuditID
                         WHERE Audits.Share = True
                        )

OP获取错误: - 参数太少预期2。

要处理此,可能会获得此错误,因为所选的任何列名都包含特殊字符。如果数据库的列名中有特殊字符,则该名称应在SQL查询中用括号括起来。因此,如果您有任何具有特殊char值的列名,请尝试[ColumnName]