Results 1 to 2 of 2

Thread: # in query

  1. #1
    Join Date
    Mar 2004
    Posts
    4

    Unanswered: # in query

    Hi,

    I have a table that includes the field `Case #`. I have no control on how it's named. When I try to write a query, the # acts as a remark character and everything right of it is ignored.

    Is there a way around this?

    Thanks!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you are right, it is a very weird situation

    urge you strongly to lobby to get the name changed

    the only thing i was able to do was copy the contents into an identical table with a different name

    first of all, i was not able to actually create a table this way

    i had to fool it like this:
    PHP Code:
    create table badcolnames
    id tinyint not null primary key auto_increment
    , `Case 2integer not null
    );
    insert into badcolnames (`Case 2`)
    values 937 )
    , ( 
    21 ) , ( 101010101 );

    create table badcolnames2
    select id
    , `Case 2` as "Case #"
     
    from badcolnames
     
    select 
    from badcolnames2 
     
    id
    ,Case #
    1,937
    2
    ,21
    3
    ,101010101 
    against this table, nothing works except a plain SELECT *

    so create and copy:
    PHP Code:
    create table badcolnames3
     
    id3 integerCase3 integer )
     
    insert into badcolnames3 
    select 
    *
     
    from badcolnames2
     
     select 
    from badcolnames3

    id3
    ,Case3
    1
    ,937
    2
    ,21
    3
    ,101010101 
    totally weird
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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