简体   繁体   English

如何将一个表的记录(特定的行,具有多个(但不是全部)列)附加到另一个表

[英]How can I append records (specific rows, with multiple (but not all) columns) from one table to another

Each day ~5000 records are uploaded to tblRecordsCurrent, at some point within the next few days when those records have been processed, they need to be moved to tblRecordsHistorical. 每天约有5000条记录上载到tblRecordsCurrent,在处理这些记录后的几天之内的某些时候,需要将它们移到tblRecordsHistorical。 Each record has a Foreign Key DataSetID that ties it to the date/time it was uploaded (Parent Table). 每个记录都有一个外键DataSetID ,可将其与上载日期/时间(父表)联系起来。

How, within vba, can I insert a single DataSet of tblRecordsCurrent into the tblRecordsHistorical from tblRecordsCurrent. 如何在vba中如何将tblRecordsCurrent的单个数据集从tblRecordsCurrent插入tblRecordsHistorical。 I cannot insert all columns as both tables contain persisted columns. 我不能插入所有列,因为两个表都包含持久列。

I can't put the entire INSERT INTO tblRecordsHistorical A, B, C, D, E, F... as it is too long for access vba. 我无法将整个INSERT INTO tblRecordsHistorical A, B, C, D, E, F... ,因为访问vba太长了。

Any ideas? 有任何想法吗?

If you save the query in your Access database, then you can execute in in VBA the following way: 如果将查询保存在Access数据库中,则可以通过以下方式在VBA中执行:

DoCmd.OpenQuery "yourQueryName", acViewNormal, acEdit

Or 要么

CurrentDb.OpenRecordset("yourQueryName")

Or 要么

CurrentDb.Execute "qryAddLoginfoRow"

This allows you to execute the query without having the query stored in your VBA code. 这使您无需将查询存储在VBA代码中即可执行查询。 But you are also able to execute this via a query in VBA : 但是您也可以通过VBA的查询执行此操作:

INSERT INTO tblRecordsHistorical (col1, col2...) 
SELECT col1, col2...
FROM tblRecordsCurrent

EDIT: 编辑:

You can create a long SQL string by concatenating the string together: 您可以通过将字符串串联在一起来创建长SQL字符串:

SQLString = "INSERT INTO tblRecordsHistorical (col1, col2...) " & _
            " SELECT ... " & _
            " FROM tblRecordsCurrent "

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将一个表的所有行追加到另一个表 - To append all rows from one table to another 我可以使用SQL将另一张表中的多行值组合为一行的多列吗? - Can I combine values from multiple rows in another table into multiple columns of one row using SQL? SQL:将一个表中的所有记录插入到另一个表中,但没有指定列 - SQL: Insert all records from one table to another table without specific the columns 根据多个条件,将记录从一个表中的特定列插入到另一表中 - inserting records from specific columns in one table to another table depending on multiple criteria 如何从另一个表中获取最后 2 条记录作为列 - How can I get last 2 records from another table as columns 如何在 SQL 中将 append 记录从一个表记录到另一个表 - How to append records from one table to another table in SQL 按多列显示一个表中的记录,该表不在另一个表中 - Display records from one table which is not in another table by multiple columns 如何从一个表中选择所有行,并根据另一表计算字段值 - How can I select all rows from one table, calculating a field value based on another table 将一个表中的行插入到具有特定模式的另一个表的列中 - Insert rows from one table to columns of another table with specific pattern 如何使用最高父表的索引将记录及其所有相关记录从一个数据库复制到另一个数据库? - How can I copy records and all its related records from one database to another database using the index of the highest parent table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM