繁体   English   中英

MS Access SQL - 在向表中添加附加列时插入查询

[英]MS Access SQL - Insert Query while adding an additional column into table

我正在使用 VBA 通过 SQL 语句将查询集插入到现有的 ms access 365 表中。

插入查询的代码(有效):

 CurrentDb.Execute "Insert Into Tablename Select temp.* From temp",dbFailOnError 'if table exists
 
 CurrentDb.Execute "Select temp.* Into Tablename From temp",dbFailOnError 'if table does not exist

但是现在,我还尝试将值添加到不在查询中的列(日志编号)到插入的查询集的表中。 因此,假设将“1”插入到这些记录的表中名为 Evtlog 的列中。

我希望将日志编号添加到 Evtlog 列中(给出语法错误):

CurrentDb.Execute "Insert Into Tablename Select temp.* From temp Set Evtlog=1",dbFailOnError 

但是我在这个声明中得到了一个错误,无论如何将“选择”与“设置”结合起来?

最好,我更愿意使用 Select 因为查询列可以更改,但我对其他解决方案持开放态度 - 例如,可以将列添加到查询集中吗?

尝试这个:

CurrentDb.Execute "Insert Into Tablename Select temp.*, 1 As EvtLog From temp",dbFailOnError 'if table exists
 
CurrentDb.Execute "Select temp.*, 1 As EvtLog Into Tablename From temp",dbFailOnError 'if table does not exist

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM