Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 452
BobMcGee Avatar asked Jun 03 '11 16:06

BobMcGee


2 Answers

"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!

like image 199
Michael Ames Avatar answered Sep 22 '22 02:09

Michael Ames


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

like image 37
paulmorriss Avatar answered Sep 22 '22 02:09

paulmorriss