简单的 MSAccess SQL UNION ALL;如何包含自动注释列值?

Simple MSAccess SQL UNION ALL; how to include an automatic annotation column value?

我正在使用 SQL 语句将数据从两个单独的 tables (A, B) 提取到 MSAccess 中的另一个 (C)。将来自 tables (A, B) 的所有列附加到目标 table (c) 中。为了使用馈送源注释数据,我在 (c) 中添加了一个“源”列。在 feeding tables 中不存在此 ‘Source’ 列中的注释信息。我希望它根据 SELECT 语句中给定的值写入 'Source' 条目。如果我只加载一个 table,这可以正常工作,但是当我使用 UNION ALL 一次加载多个 table 时,它就不起作用。下面的代码会导致输入 'Source' 值的提示,该值将应用于所有条目。我做错了什么?

INSERT INTO Hist_PO (Plant, Material_No, Date_Delivery, Quantity_Ordered, Quantity_Recieved, Source) SELECT Plant, Material, [Delivery date], [Scheduled Quantity], [Quantity delivered], “” FROM ( SELECT Plant, Material, [Delivery date], [Scheduled Quantity], [Quantity delivered], "Source_A" FROM [Table_A] UNION ALL SELECT Plant, Material, [Delivery date], "Source_B" FROM [Table_B]);

您可以尝试下面的查询 - 对于联合,您的 select 语句应该具有相等的列数

INSERT INTO Hist_PO (Plant, Material_No, Date_Delivery, Quantity_Ordered, Quantity_Recieved, Source)
SELECT Plant, Material, [Delivery date], [Scheduled Quantity], [Quantity delivered], source 
FROM 
(
SELECT Plant, Material, [Delivery date], [Scheduled Quantity], [Quantity delivered], "Source_A"  as source FROM [Table_A]
UNION ALL
SELECT Plant, Material, [Delivery date],0,0 "Source_B" FROM [Table_B]
)

我想通了...SAP_Instance 标有 [banana] 个条目。

INSERT INTO [Test-Table] ( Material_No, Date_Delivery, SAP_Instance )
SELECT Material, [Delivery date], [banana]
FROM (SELECT Material, [Delivery date], 'SAP_EU' as [banana]

FROM [PO-ME80FN-EU]

UNION ALL

SELECT Material, [Delivery date], 'SAP_NAM'  as [banana]

FROM [PO-ME80FN-NAM]
);