Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Unanswered: I Cant select column names with Spaces

    Hello,

    I'm just a frustrated noob trying to get past my first DB Program. My goal is to get relational data from different tables all ordered by a certain field


    Ive noticed early on that i cannot select a column when its name has a space
    EX:
    I have to type:
    sql = "SELECT [Chart Number] FROM Table1"

    If I write:
    sql = "SELECT Chart Number FROM Table1"
    I get an error:
    "... Cant find Column Name Chart..."


    Now the statement i want to use is

    sql = "SELECT [PT.Chart Number],[PT.Last Name],[CA.Case Number] FROM Table1 AS PT INNER JOIN Table2 AS CA ON PT.Chart Number = CA.Chart Number ORDER BY PT.Chart Number"

    When i Debug i get the same type of error ("... Can't find column name PT.Chart... ")

    I'm new to sql so i dont know if my syntax is off. Can someone please help
    Ive tried with brackets, without brackets. With and without "AS"

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by JuicyMike View Post
    I'm new to sql so i dont know if my syntax is off.
    yes, it is

    put the brackets around the column name only, not both table and column name
    Code:
    SELECT PT.[Chart Number]
         , PT.[Last Name]
         , CA.[Case Number] 
      FROM Table1 AS PT 
    INNER 
      JOIN Table2 AS CA 
        ON CA.[Chart Number] = PT.[Chart Number]
    ORDER 
        BY PT.[Chart Number]
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Also, don't use spaces in column names. Partly for this reason.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Apr 2012
    Posts
    4
    Thanks a lot for the replies, i knew it had to do with the syntax.

    Unfortunately the database belongs to another program i just want to connect to it to extract data

Tags for this Thread

Posting Permissions

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