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

problem with imported Db column name

Status
Not open for further replies.

excession

Programmer
Sep 22, 2004
111
GB
I am trying to extract data from an imported database (originally MS Access). Unfortunately one of the column names has a space in it which is causing me problems.

I need to be able to refernce this column but I get a syntax error or a unknown column error when I try because mySQL doesn't accept the column name with it's annoying space in it.

How do I get around this problem?

Thanks



 
MySQL table and column names can contain spaces or other special characters, but any such names must always be enclosed within "backticks" (grave-accent characters). For example, SELECT `field one` FROM `table one`.
 
I've already tried that.

The problem column name is 'Chassis No'

If I try:
select 'Chassis No' from reg;
I get :

| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
| Chassis No |
+------------+
778 rows in set (0.00 sec)

The table:


+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| RegID | int(10) | | PRI | NULL | auto_increment |
| RegNo | varchar(50) | | PRI | | |
| CustID | int(10) | YES | MUL | NULL | |
| Make | varchar(50) | YES | | NULL | |
| Model | varchar(50) | YES | | NULL | |
| Chassis No | varchar(50) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)

 
ah ha, but if I use the ` instead of the ' it works.

Thanks - me being daft again I'm afraid...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top