问题
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