MS-Access Query中的语法错误(缺少运算符)

时间:2012-04-20 16:15:56

标签: sql ms-access syntax

以下查询给出了"(missing operator)"语法错误。所需的输出是表[dbo_tbl*]和视图[vw_*]的数据组合。我使用过的所有密钥都存在。有什么想法吗?

SELECT dbo_tbl_BOD.fpartno AS PartNumber,
      dbo_tbl_BOD.frev AS RevisionIssue,
      vw_DOCSwType.DocID,
      vw_DRHRelfilter.Rev,
      vw_DOCSwType.DocTypeDesc,
      vw_DOCSwType.DocDesc,
      vw_DOCSwType.DwgNoLegacy,
      vw_DOCSwType.FileLocationOld,
      vw_DRHRelfilter.DateCreated,
      vw_DOCSwType.CreatedBy,
      vw_DRHRelfilter.Rel,
      vw_DRHRelfilter.RelLink
FROM dbo_tbl_BOD
LEFT JOIN vw_DRHRelfilter
      ON ((dbo_tbl_BOD.DocID=vw_DRHRelfilter.DocID)
     AND (dbo_tbl_BOD.frev=vw_DRHRelfilter.Rev))
 LEFT JOIN vw_DOCSwType
      ON (dbo_tbl_BOD.DocID=vw_DOCSwType.DocID)
ORDER BY PartNumber;

1 个答案:

答案 0 :(得分:7)

使用Access,每个联接都需要括号,例如:

SELECT dbo_tbl_BOD.fpartno AS PartNumber,
dbo_tbl_BOD.frev AS RevisionIssue,
vw_DOCSwType.DocID,
vw_DRHRelfilter.Rev,
vw_DOCSwType.DocTypeDesc,
vw_DOCSwType.DocDesc,
vw_DOCSwType.DwgNoLegacy,
vw_DOCSwType.FileLocationOld,
vw_DRHRelfilter.DateCreated,
vw_DOCSwType.CreatedBy,
vw_DRHRelfilter.Rel,
vw_DRHRelfilter.RelLink
FROM (dbo_tbl_BOD
LEFT JOIN vw_DRHRelfilter
ON dbo_tbl_BOD.DocID=vw_DRHRelfilter.DocID
AND dbo_tbl_BOD.frev=vw_DRHRelfilter.Rev)
LEFT JOIN
vw_DOCSwType
ON dbo_tbl_BOD.DocID=vw_DOCSwType.DocID
ORDER BY PartNumber;

如果您有MS Access的副本,则可以使用查询设计窗口轻松查看所需的括号以构建联接。

您可以使用VBA检查字段类型,例如:

Dim rs As DAO.Recordset
Dim fld As DAO.Field

Set rs = CurrentDb.OpenRecordset("query1")
For Each fld In rs.Fields
    Debug.Print fld.SourceField, fld.SourceTable, _
        DLookup("SQLName", "DataTypeEnum", "DataValue=" & fld.Type)
Next

表DataTypeEnum包含fld.type返回的数值的文本描述。

DataValue  SQLName
1   Boolean
2   Byte
3   Integer
4   Long
5   Currency
6   Single
7   Double
8   Date
9   Binary
10  Text
11  LongBinary
12  Memo
15  GUID
16  BigInt
17  VarBinary
18  Char
19  Numeric
20  Decimal
21  Float
22  Time
23  TimeStamp