0

我有一种感觉,这里一定有一个我看不到的愚蠢错误,但我已经盯着它看了那么久,我不知所措。我正在通过 VBA 生成一条 SQL 语句,但我不断收到一个奇怪的错误。SQL出来看起来像这样:

SELECT c.Junction_ID AS [ID], c.[First_Name] AS [First Name], c.[Last_Name] AS [Last Name], 
  c.Location, c.Start_Date AS [Start Date], c.End_Date AS [End Date], 
  s.Helpful_Scale AS [Helpfulness], s.Memory_Scale AS [Memory] 
FROM nka_ClassList_Unique c 
INNER JOIN nka_Supplemental s ON c.Junction_ID = s.Junction_ID 
INNER JOIN nka_ClassList_Unique_Mgrs m ON m.Location = c.Location 
  AND ((c.Start_Date BETWEEN m.StartDate AND m.EndDate) 
    OR (c.End_Date BETWEEN m.StartDate AND m.EndDate) 
    OR (m.StartDate BETWEEN c.Start_Date AND c.End_Date) 
    OR (m.EndDate BETWEEN c.Start_Date AND c.End_Date)) 
WHERE ((c.Management = False) AND (c.Dist_Manager = False) 
  AND (m.Junction_ID = 129880) AND (c.Location = "DEC"))

Access 引发以下错误(我已将其格式化为适合屏幕):

Syntax error (missing operator) in query expression
`c.Junction_ID = s.Junction_ID INNER JOIN nka_Sprint1_ClassList_Unique_Mgrs m 
  ON m.Location = c.Locatio'.

什么会导致 Access 通过字段名称中途停止解析此查询?它与在一定数量的字符后停止没有任何关系。即使我更改SELECT表别名语句的长度,它也总是停在c.Locatio.

关于为什么会这样做的任何想法?我在这里忽略了一些愚蠢的东西。

4

1 回答 1

3

连接两个以上的表时,MSAccess 有点挑剔。它需要连接之间的括号,

SELECT c.junction_id   AS [ID], 
       c.[first_name]  AS [First Name], 
       c.[last_name]   AS [Last Name], 
       c.location, 
       c.start_date    AS [Start Date], 
       c.end_date      AS [End Date], 
       s.helpful_scale AS [Helpfulness], 
       s.memory_scale  AS [Memory] 
FROM   ((nka_classlist_unique c 
       INNER JOIN nka_supplemental s 
               ON c.junction_id = s.junction_id)  // <<== observe the parenthesis
       INNER JOIN nka_classlist_unique_mgrs m 
               ON m.location = c.location 
                  AND ( ( c.start_date BETWEEN m.startdate AND m.enddate ) 
                         OR ( c.end_date BETWEEN m.startdate AND m.enddate ) 
                         OR ( m.startdate BETWEEN c.start_date AND c.end_date ) 
                         OR ( m.enddate BETWEEN c.start_date AND c.end_date ) ) )
WHERE  ( ( c.management = false ) 
         AND ( c.dist_manager = false ) 
         AND ( m.junction_id = 129880 ) 
         AND ( c.location = "dec" ) ) 
于 2013-04-26T18:13:05.483 回答