我有8个查询,所有查询都具有相同的设计等,以便创建一个新表,但要针对不同的条件,并希望将它们附加到一个表中。
是否可以使用VBA代码或UNION进行此操作?
<!ENTITY % role.att
'role NMTOKEN #IMPLIED'>
<!ENTITY % common.att
'id ID #IMPLIED
%role.att;'>
<!ATTLIST notice %common.att;>
这是两个表,
SELECT tbl_SCCMQ.CONTRACT_ACCOUNT_NUMBER, tbl_SCCMQ.BP_Partner, tbl_SCCMQ.CONTRACT_NUMBER, tbl_SCCMQ.BILL_TO_DATE, tbl_SCCMQ.CONTRACT_START_DATE, tbl_SCCMQ.AGEING_DATE, tbl_SCCMQ.DateDiff, tbl_SCCMQ.PAYMENT_TYPE, tbl_SCCMQ.BP_Type, tbl_SCCMQ.[Next Bill Due Date], tbl_SCCMQ.[BAND], tbl_SCCMQ.RAG, tbl_SCCMQ.BILL_STATUS INTO tbl_01_Resi_CCQ_R1_4_Never_Billed_NoSS
FROM tbl_SCCMQ
WHERE (((tbl_SCCMQ.BP_Type)="B2C") AND ((tbl_SCCMQ.RAG) Like "R*") AND ((tbl_SCCMQ.BILL_STATUS)="First") AND ((tbl_SCCMQ.BILL_BLOCK) Is Null) AND ((tbl_SCCMQ.BILL_LOCK) Is Null) AND ((tbl_SCCMQ.INVOICE_LOCK) Is Null));
,希望它们全部导入主表“数据”
我对Access和VBA等还很陌生。
答案 0 :(得分:0)
您的问题看起来像您知道如何解决该问题。
注意:查询1到8必须具有相同数量的字段,并且每个字段的顺序位置(在您的问题中声明)的数据类型必须一致。
SQL语法从查询中创建新表(数据):
select *
INTO Data
from (
select * from query1
union all
select * from query2
union all
...
union all
select * from query8
) as queryData
或 将数据附加到现有表的SQL语法:
INSERT INTO Data
select *
from (
select * from query1
union all
select * from query2
union all
...
union all
select * from query8
) as queryData
VBA语法以代码形式运行查询:
dim db as dao.database: set db = Currentdb
dim strSQL as string
strSQL = "...." ' as above
db.execute strSQL