表[Event]有字段[ID]和[ReferenceEvent]。 [ReferenceEvent]是指[Event]上另一条记录的[ID]号。
表[BOM]包含[BlueprintID]和[EventID]字段。
我有一个查询[BOM]并在找到匹配[BlueprintID]的[Event.ID]和[ReferenceEvent]的记录时返回[BlueprintID]和[EventID]。
简单地说,此查询告诉我用于事件的蓝图是否也用于参考事件。这是[BOM匹配参考查询]。
然后,我只需将[BOM匹配参考查询]和LEFT JOIN [ReferenceEvent]返回到[BlueprintID]。这是[BOMReportQuery]。
到目前为止,一切都完美无缺!
最后,我将[BOMReportQuery]设置为报告的记录源。当我运行报告时,出现以下错误。
“指定的字段'Event.ID'可以引用SQL语句的FROM子句中列出的多个表。”
我通过仅删除LEFT Join到[BOM Match Ref Query]来测试[BOMReportQuery]。报告运行得很好。我还测试了直接为差异报告设置[BOM匹配参考查询]作为记录源。该报告完美无缺。出现错误的唯一情况是我加入两个报告并运行报告。当我查看查询数据结果时,只有在我运行报告时才会出现错误。
请帮忙。我傻眼了。我正在使用Access。
BOM匹配参考查询:
SELECT BOM.BlueprintID AS RefBlueprintID,
BOM_1.EventID
FROM (
BOM INNER JOIN BOM AS BOM_1
ON BOM.BlueprintID = BOM_1.BlueprintID
)
INNER JOIN Event
ON (BOM.EventID = Event.ID)
AND (BOM_1.EventID = Event.ReferenceEvent)
GROUP BY BOM.BlueprintID,
BOM_1.EventID;
BOMReportQuery:
SELECT Event.Project,
Event.Event AS Event1,
Event.Assembly,
PartQuery.FordPartNo,
PartQuery.GMPartNo,
Blueprint.Revision,
PartQuery.CommonName,
BOM.Quantity,
Supplier.SupplierName,
Blueprint.ID,
PartQuery.SelectFit,
BOM.SelectFitNote,
DLookUp("IssueDate", "DA", "BlueprintID=" & [BlueprintID] & " AND SupplierID=1") AS InHouseIssueDate,
IIf([InHouseIssueDate], True, False) AS Issued,
[Project] & " " & [Event] & " " & [Assembly] & " at " & [Quantity] & "per" AS ProjectEventAssy,
PartQuery.PrimaryPartNo,
PartQuery.PrimaryPartName,
BOM.BeginDate,
BOM.EndDate,
BOM.Printed,
Event.ID,
[BOM Match Ref Query].EventID
FROM (
(
(
(
BOM LEFT JOIN Event
ON BOM.EventID = Event.ID
) LEFT JOIN Blueprint
ON BOM.BlueprintID = Blueprint.ID
) LEFT JOIN PartQuery
ON Blueprint.PartID = PartQuery.ID
) LEFT JOIN Supplier
ON PartQuery.SupplierID = Supplier.ID
)
/*Error appears (on report only) when adding the following line*/
LEFT JOIN [BOM Match Ref Query]
ON BOM.BlueprintID = [BOM Match Ref Query].RefBlueprintID
ORDER BY PartQuery.FordPartNoBase,
PartQuery.FordPartNo,
PartQuery.PrimaryPartNo;