'CREATE TABLE' generates Run-time error '3290'

℡╲_俬逩灬. 提交于 2021-01-27 12:52:14

问题


I have a syntax issue in the first CREATE TABLE statement.

I'm receiving the following VBA error:

Run-time error '3290'

The goal is to move the distinct data to a new table dependent on values in specific columns. Afterwards the original table is cleared, and every distinct value will be inserted again. The temporary table will be deleted afterwards.

' ** Issue here ** '
db.Execute ("CREATE TABLE tTemp AS (SELECT DISTINCT History_Date, Sedol, Selskabsnavn, MarketCap, JQScore, JQ_Rank, Value_Rank, Quality_Rank, Momentum_Rank FROM JQHistory)")

db.Execute ("DELETE * FROM JQHistory")
db.Execute ("SELECT * FROM tTemp INTO JQHistory")
db.Execute ("DROP TABLE tTemp")

This code is being run from within MS Excel.


回答1:


You already have the syntax to make this work in the third statement, although it's not quite correct.

The first line should be db.Execute ("SELECT DISTINCT <list of fields> INTO tTemp FROM JQHistory")

The third statement should be: db.Execute ("INSERT INTO JQHistory SELECT <list of fields> FROM tTemp")




回答2:


Final solution:

db.Execute ("SELECT DISTINCT History_Date, Sedol, Selskabsnavn, MarketCap, JQScore, JQ_Rank, Value_Rank, Quality_Rank, Momentum_Rank INTO tTemp FROM JQHISTORY ORDER BY History_Date")
db.Execute ("DELETE * FROM JQHistory")
db.Execute ("ALTER TABLE JQHistory ALTER COLUMN Id COUNTER (1, 1)")
db.Execute ("INSERT INTO JQHistory SELECT * FROM tTemp")
db.Execute ("DROP TABLE tTemp")


来源:https://stackoverflow.com/questions/56645798/create-table-generates-run-time-error-3290

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!