6

The following query is giving me the "(missing operator)" syntax error. The desired output is a combination of data from tables [dbo_tbl*] and views [vw_*]. All of the keys I've used exist. Any ideas?

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;
2
  • Thanks for the edit bluefeet. Newbie here, is there information on formatting for entry on this site somewhere? My formatting was stripped from my original text posting.
    – cixelsyd
    Apr 20, 2012 at 19:01
  • To format text as code, select the text then press the code sample button which looks like "{}". You can also select the text then press Ctrl+k. More information about editing options here: stackoverflow.com/editing-help
    – HansUp
    Apr 20, 2012 at 21:36

1 Answer 1

8

With Access, each join needs parentheses, say:

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;

If you have a copy of MS Access, you can easily see the required parentheses by using the query design window to build your joins.

You can use VBA to check field types, for example:

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

The table DataTypeEnum contains text descriptions for the numeric values returned by 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
5
  • Thanks @Remou. Now I'm getting a type mismatch error when executing the query.
    – cixelsyd
    Apr 20, 2012 at 19:20
  • This is likely to be due to one of the matches being of different type, for example matching a text type to a numeric type field (column), for example dbo_tbl_BOD.frev=vw_DRHRelfilter.Rev
    – Fionnuala
    Apr 20, 2012 at 19:22
  • I can easily see the datatype in my Access tables, but how do I determine the datatype returned in views?
    – cixelsyd
    Apr 20, 2012 at 19:42
  • I do not get your point. Do you not know your data types? Are you not working within Access?
    – Fionnuala
    Apr 20, 2012 at 19:47
  • Sorry for all the newbie questions. Working in Access. Is there a way to display the data type returned in a view / query? Otherwise I need to resolve back through the queries to the originating table to match up data type.
    – cixelsyd
    Apr 20, 2012 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.