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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a field name with underscores in SQL

Status
Not open for further replies.

Layth

IS-IT--Management
Jun 7, 2005
44
US
I have a database with linked tables to another database. I have pulled the information that I need from these tables through a make-table query. Now I want to query the new table, but I run into a problem.

Certain fields in the original database had fields with the same name such as code, and Access renamed the field with the table it was associated with such as _SYSTEM_RATE_CODE and _SYSTEM_ADJ_CODE.

When I try to do a Where statement on one of these fields such as:
Select *
FROM [Primary Table]
WHERE _SYSTEM_RATE_CODE = 'cc';

I get a "Syntax error in query expression".

I believe it's the underscores causing the problem as I rename the field to just RATECODE, the query works fine, but I can't change the table name because every time you have the make-table query update the table, it changes the field back to _SYSTEM_RATE_CODE.

My question is how do you perform a SQL query with underscores in the title, or is there a workaround.

Any help is always greatly appreciated!

thanks,

Layth
 
how about this:

Select *
FROM [Primary Table]
WHERE [_SYSTEM_RATE_CODE] = 'cc';


just enclose them in square brackets...

-DNG
 
AWESOME! That is just what I needed

THANKS

Layth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top