Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query syntax: using reserved keywords

Status
Not open for further replies.

Sanx

Programmer
Jun 3, 2005
2
NZ
I'm writing a small program to access a database and pull some info out of it.

It's not my database, so I can't rename any of the tables. The table I'm interested in is called 'USER' - a reserved SQL keyword. The database can either be a file-based JET database or hosted on SQL.

The problem is the exact SQL syntax needed. Within SQL hosted DBs, the query can be made to work by delimiting (quoting) the table names as follows:

SELECT "NAME" FROM "USER" WHERE ID = 1

That query when run against the JET database results in the error "Syntax error (missing operator) in query expression ...". FYI: 'ID' is an Autonumber (integer) column. I've tried various query formats without success. Others I've tried include:

SELECT 'NAME' FROM 'USER' WHERE ID = 1
SELECT "USER.NAME" WHERE "USER.ID" = 1
SELECT 'USER.NAME' WHERE 'USER.ID' = 1

All of these queries work just fine when run against a SQL-hosted database. I need a query which works on both Access and SQL. Any ideas? Thanks.
 
Don't worry, found the solution. Instead of delimiting the reserved keywords in quotes, use square brackets, i.e:

SELECT NAME FROM [USER] WHRE ID = 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top