Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    17

    Unanswered: How to query a column with special character as its column name

    I have a column called htstuff# in the table Stuffs. When I type
    select htstuff# from Stuffs , I get a syntax error. I tried Select Stuffs.htstuff# from Stuffs even that gave me an error. But if i use select * from Stuffs, it works fine. I cannot change the column name, so is there any way to query just the htstuff# column name.
    -Thanks
    Kangan

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I doubt it. The # is an operator that is used to surround dates that need to be converted.

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    probably your mother already told you that a little discipline in field naming will save you lots of heartache later.

    no idea if it will work, but have you tried
    strSQL = "SELECT hstuff" & chr$(asc("#")) & " FROM whatever

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select [htstuff#] from Stuffs


    rudy
    http://r937.com/

  5. #5
    Join Date
    Oct 2003
    Posts
    17
    Thanks,
    select [htstuff#] from Calls worked fine.
    -Kangan
    kr

  6. #6
    Join Date
    Oct 2003
    Posts
    706

    Red face

    Generally, enclosing the name in brackets [stuff#] will do the trick .. however, you really don't want special characters in column-names. Nor reserved words. Doing so is simply going to create a lot of "ripple" throughout the application -- you're constantly compensating for the poor choice of names -- and that soaks up time=money.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

Posting Permissions

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