簡體   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