我觉得这里肯定有一个我无法看到的愚蠢错误,但是我已经盯着它看了很长时间以至于我不知所措。我通过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
。
有关为何会这样做的任何想法?我必须有一些愚蠢的东西,我可以忽略这里。
答案 0 :(得分: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" ) )