Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Posts
    1

    Unanswered: Problem with spaces in column names?

    I created a simple table. One of the columns had a name with a space, .e.g., 'Last Name'. When trying to insert a record with MFC (ODBC), an exception is thrown (by MyODBC I assume) complaining of a syntax error in the INSERT statement. However, when I create an identical table but with no space in the column name, e.g., 'LastName', the insert works fine. Anyone now what the problem might be?

    I'm a MySQL newbie, so be gentle. And, yes, I'm locked into MFC. Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    two options:

    1. rename your columns and remove the spaces

    2. use back ticks

    e.g. select `Last Name` from yourtable...


    rudy
    http://r937.com/

  3. #3
    Join Date
    Sep 2002
    Location
    Montreal, Canada
    Posts
    224
    Provided Answers: 1

    Re: Problem with spaces in column names?

    Originally posted by mcgee
    I created a simple table. One of the columns had a name with a space, .e.g., 'Last Name'. When trying to insert a record with MFC (ODBC), an exception is thrown (by MyODBC I assume) complaining of a syntax error in the INSERT statement. However, when I create an identical table but with no space in the column name, e.g., 'LastName', the insert works fine. Anyone now what the problem might be?

    I'm a MySQL newbie, so be gentle. And, yes, I'm locked into MFC. Thanks.
    Avoid using names with spaces. That way, you're gonna be pretty "standard", i.e. you'll avoid many many problems if you ever want to access that database with other tools. And avoir having names longer than 18 characters...

    These are rules I always follow and I have a portable application accessing more than a dozen databases through ODBC. Never had any problem related to column/view/table/index names...

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •