Microsoft Access does not like a table field name in a SQL Query

你。 提交于 2020-01-06 04:05:35

问题


I have the following SQL query that I am trying to run inside Microsoft Access 2010 and I get an error( Syntax error in INSERT INTO statement) then it highlights the field "Level" if I rename the field to "Level1" it works. The problem is that I can't rename the field because I have several SQL queries in PHP that I rely on the field name "Level" Any ideas of why it would throw an error.

The reason I am running the query is to copy data from an external ODBC sqlite database using linked tables. I do have several other INSERT INTO queries working this way. If there is another way please let me know. I have the query in some VB code that I use DoCmd.RunSQL

INSERT INTO MinorStats1 ( PlayerID,YearNumber,TeamID,Level,B_PA,B_AB,B_Hits,B_Doubles,B_Triples,B_HR,B_RBI,B_BB,B_K,B_TB,B_AVG,B_SLG,B_OPS,B_OBP,B_FPCT,B_SB,B_CS,P_Wins,P_Losses,P_Saves,P_GS,P_OutsPitched,P_BF,P_Hits,P_HR,P_BB,P_K,P_ER,P_ERA)SELECT PlayerID,YearNumber,TeamID,Level,B_PA,B_AB,B_Hits,B_Doubles,B_Triples,B_HR,B_RBI,B_BB,B_K,B_TB,B_AVG,B_SLG,B_OPS,B_OBP,B_FPCT,B_SB,B_CS,P_Wins,P_Losses,P_Saves,P_GS,P_OutsPitched,P_BF,P_Hits,P_HR,P_BB,P_K,P_ER,P_ERA FROM MinorStats

回答1:


Enclose level in square brackets as follows:

INSERT INTO MinorStats1 ( PlayerID,YearNumber,TeamID,[Level],B_PA,B_AB,B_Hits,B_Doubles,B_Triples,B_HR,B_RBI,B_BB,B_K,B_TB,B_AVG,B_SLG,B_OPS,B_OBP,B_FPCT,B_SB,B_CS,P_Wins,P_Losses,P_Saves,P_GS,P_OutsPitched,P_BF,P_Hits,P_HR,P_BB,P_K,P_ER,P_ERA)SELECT PlayerID,YearNumber,TeamID,[Level],B_PA,B_AB,B_Hits,B_Doubles,B_Triples,B_HR,B_RBI,B_BB,B_K,B_TB,B_AVG,B_SLG,B_OPS,B_OBP,B_FPCT,B_SB,B_CS,P_Wins,P_Losses,P_Saves,P_GS,P_OutsPitched,P_BF,P_Hits,P_HR,P_BB,P_K,P_ER,P_ERA FROM MinorStats

You need to do this because level is a reserved word in Access. For a complete list of reserved words, see http://support.microsoft.com/kb/286335.




回答2:


You just need to surround [Level] (which is a reserved word evidently) with brackets.



来源:https://stackoverflow.com/questions/8812652/microsoft-access-does-not-like-a-table-field-name-in-a-sql-query

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