T
tigger
Hi there, can anyone help?
I apologise in advance for hurting your eyes ...
I am trying to create a query which joins several tables with several rules
and criteria. The inner joins work perfectly but I am trying to do a left
join to show all records and I know it is simply a syntax problem - can't see
where to put my brackets
I need to:
Left join tblNCRActions to tblNCRs on NCR ID
then
Left join tblNCRActions to tblAuditDetails by Audit ID (or tblNCRs if this
is better?)
Inner join tblAuditDetails to tblNCRs by Audit ID
then
Inner join tblAuditor to tblAuditDetails by Auditor ID
So that I can show all audits, corresponding NCRs and any actions relating
to the NCRs in a report.
Code:
SELECT tblAuditDetails.[Audit ID] AS [tblAuditDetails_Audit ID],
tblAuditDetails.[Audit title], tblAuditor.[Auditor name], tblNCRs.[NCR ID],
tblNCRs.NCRTitle, tblNCRs.[Agreed date], tblNCRs.[Baseline target],
tblNCRs.[Forecast target], tblNCRs.Status, tblNCRActions.[Agreed action],
tblNCRActions.Actionee, tblNCRActions.Status
FROM (tblAuditor INNER JOIN (tblAuditDetails INNER JOIN tblNCRs
ON tblAuditDetails.[Audit ID]=tblNCRs.[Audit ID]) ON tblAuditor.[Auditor
ID]=tblAuditDetails.Auditor) LEFT JOIN tblNCRActions
ON (tblAuditDetails.[Audit ID]=tblNCRActions.[Audit ID])
AND (tblNCRs.[NCR ID]=tblNCRActions.[NCR ID])
WHERE tblAuditDetails.[Audit ID]= " & varAuditRef & "
Thanks for the help!
I apologise in advance for hurting your eyes ...
I am trying to create a query which joins several tables with several rules
and criteria. The inner joins work perfectly but I am trying to do a left
join to show all records and I know it is simply a syntax problem - can't see
where to put my brackets
I need to:
Left join tblNCRActions to tblNCRs on NCR ID
then
Left join tblNCRActions to tblAuditDetails by Audit ID (or tblNCRs if this
is better?)
Inner join tblAuditDetails to tblNCRs by Audit ID
then
Inner join tblAuditor to tblAuditDetails by Auditor ID
So that I can show all audits, corresponding NCRs and any actions relating
to the NCRs in a report.
Code:
SELECT tblAuditDetails.[Audit ID] AS [tblAuditDetails_Audit ID],
tblAuditDetails.[Audit title], tblAuditor.[Auditor name], tblNCRs.[NCR ID],
tblNCRs.NCRTitle, tblNCRs.[Agreed date], tblNCRs.[Baseline target],
tblNCRs.[Forecast target], tblNCRs.Status, tblNCRActions.[Agreed action],
tblNCRActions.Actionee, tblNCRActions.Status
FROM (tblAuditor INNER JOIN (tblAuditDetails INNER JOIN tblNCRs
ON tblAuditDetails.[Audit ID]=tblNCRs.[Audit ID]) ON tblAuditor.[Auditor
ID]=tblAuditDetails.Auditor) LEFT JOIN tblNCRActions
ON (tblAuditDetails.[Audit ID]=tblNCRActions.[Audit ID])
AND (tblNCRs.[NCR ID]=tblNCRActions.[NCR ID])
WHERE tblAuditDetails.[Audit ID]= " & varAuditRef & "
Thanks for the help!