Why is this very simple SQL query failing in MS Access?

寵の児 提交于 2019-12-19 07:39:20

问题


I have a query that by all rights should not possibly fail, and I can't for the life of me figure out why

INSERT INTO Grocery_Store_Prices(Store,Item,Brand,Price,Unit,Quantity,Note) 
VALUES("Kroger","Cheesy Poof","Cartman",0.51,"fart",15,"what is going on");

When I try to run the query I get "Syntax error in INSERT INTO statement" with the Note field highlighted. If I omit the Note field and its value, the query works fine. Is there something really obvious I'm missing, or is there an Jet SQL quirk buried here???

The table it's acting on is: Grocery_Store_Prices

  • ID -- autonumber primary key
  • Store -- Text
  • Date -- Date/Time
  • Item -- Text
  • Brand -- Text
  • Price -- Currency
  • Unit -- Text
  • Quantity -- Number (double)
  • Note -- Text.

回答1:


"Note" is a reserved word in Microsoft Access. You need to surround it with square brackets:

INSERT INTO Grocery_Store_Prices(Store,Item,Brand,Price,Unit,Quantity,[Note])
VALUES("Kroger","Cheesy Poof","Cartman",0.51,"fart",15,"what the ____");

Helpful list of reserved words here: http://support.microsoft.com/kb/286335

Some consider it best practice to always encase field names in square brackets, just so you don't have to worry about it.

Good luck!




回答2:


Note is a reserved word, so try renaming that column.



来源:https://stackoverflow.com/questions/6229785/why-is-this-very-simple-sql-query-failing-in-ms-access

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