我有这个查询在SQL
服务器中工作正常,但在Access中没有,我在转换它时遇到问题。我一直听说JET
缺少某些TSQL
功能,我认为复杂的连接就是其中之一。
SELECT C.[Position], TT.[Description] as TrainingType, T.ProgramTitle, T.ProgramSubTitle, T.ProgramCode, ET.CompletedDate
from HR_Curriculum C
LEFT JOIN HR_Trainings T ON C.TrainingID = T.TrainingID
LEFT JOIN HR_TrainingTypes TT ON T.TrainingTypeID = TT.TrainingTypeID
LEFT JOIN HR_EmployeeTrainings ET ON C.TrainingID = ET.TrainingID
AND (ET.AvantiRecID IS NULL OR ET.AvantiRecID = '637')
where ( c.[Position] = 'Customer Service Representative'
OR C.[Position] = 'All Employees')
order by [Position], Description, ProgramTitle
我尝试在WHERE子句中放下额外的连接子句,但由于某种原因,这不会产生正确的记录数。
答案 0 :(得分:2)
如果JOIN
中有多个ms-access
,则需要用括号括起来:
SELECT C.[Position], TT.[Description] as TrainingType, T.ProgramTitle, T.ProgramSubTitle, T.ProgramCode, ET.CompletedDate
from (((HR_Curriculum C
LEFT JOIN HR_Trainings T ON C.TrainingID = T.TrainingID)
LEFT JOIN HR_TrainingTypes TT ON T.TrainingTypeID = TT.TrainingTypeID)
LEFT JOIN HR_EmployeeTrainings ET ON C.TrainingID = ET.TrainingID
AND (ET.AvantiRecID IS NULL OR ET.AvantiRecID = '637'))
where ( c.[Position] = 'Customer Service Representative'
OR C.[Position] = 'All Employees')
order by [Position], Description, ProgramTitle
或者您将遇到Missing Operator
错误
答案 1 :(得分:1)
检查您的表别名是否以'as'表示。 Access不喜欢[tablename] [alias],而是将[tablename]作为[alias]。我知道复杂的左连接不应该是一个问题,但如果它返回一些连接错误,Access可能会阻塞别名延迟。我也会尝试查询ET表上的限制,然后将其加入到更大的查询中。我注意到,尝试对左或右连接中涉及的记录设置限制通常不会产生正确的记录,因为Access将在连接后限制集合。