我正在尝试通过其SSN提取一组员工的所有帐户。同时还通过其FA编号提取所有帐户(包括他们管理的帐户以及属于自己的帐户)。
这是我到目前为止的代码。 SSN联接正在工作,但是我在最后一次联接时遇到了麻烦,将emp_id连接到FA_emp_id
SELECT [Employee List].ID,
[Employee List].FirstName,
[Employee List].LastName,
dbo_person.prsn_ssn_id,
dbo_person.prsn_emp_id,
Left([dbo_account_holder]![account_id],8) AS Account,
dbo_account_holder.holder_nickname,
dbo_account_holder.holder_reference_name
FROM ((([Employee List] LEFT JOIN dbo_person ON [Employee List].emp_id = dbo_person.prsn_emp_id)
LEFT JOIN dbo_account_holder ON dbo_person.prsn_ssn_id = dbo_account_holder.holder_ssn_id)
LEFT JOIN dbo_account ON dbo_account_holder.account_id = dbo_account.account_id)
LEFT JOIN dbo_account ON [Employee List].emp_id = dbo_account.fa_emp_id
WHERE (((dbo_account.date_account_closed) Is Null));
答案 0 :(得分:0)
尝试避免不愉快的()
,并且不要在其中有条件的情况下使用左联接表的列。如果执行此操作,那么此条件将作为内部联接工作 将条件添加到相关的on子句
SELECT [Employee List].ID,
[Employee List].FirstName,
[Employee List].LastName,
dbo_person.prsn_ssn_id,
dbo_person.prsn_emp_id,
Left([dbo_account_holder]![account_id],8) AS Account,
dbo_account_holder.holder_nickname,
dbo_account_holder.holder_reference_name
FROM [Employee List]
LEFT JOIN dbo_person ON [Employee List].emp_id = dbo_person.prsn_emp_id
LEFT JOIN dbo_account_holder ON dbo_person.prsn_ssn_id = dbo_account_holder.holder_ssn_id
LEFT JOIN dbo_account ON dbo_account_holder.account_id = dbo_account.account_id
LEFT JOIN dbo_account ON [Employee List].emp_id = dbo_account.fa_emp_id
AND dbo_account.date_account_closed Is Null;