Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Unanswered: Reserved Word Problem

    I have a table in my database which having a field named "user".
    When i try to issue a SQL query:
    SELECT * FROM table_name WHERE user = 'ABC';
    it always display me all the data in the table.
    When i check through the reserved word list, i found that user is a reserved word.
    Anyway i can retrieve the data with user = 'ABC'?

  2. #2
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    Try this:
    Code:
    SELECT * FROM table_name WHERE "user"= 'ABC';

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    USER is a special register. If you don't use delimited identifiers or qualify the column with the table name (or the table's correlation name), DB2 will resolve the expression to the special register. So you have the following options:
    Code:
    SELECT * FROM table_name WHERE "USER"= 'ABC'
    
    SELECT * FROM table_name WHERE table_name.user = 'ABC'
    
    SELECT * FROM table_name AS t WHERE t.user = 'ABC'
    Notes:
    * the trailing ';' is not part of the SQL statement itself
    * do not use lower-case in the delimited identifier, i.e. "user" because that will do a case-sensitive search for the column name is bound to fail if you didn't use delimited identifiers when creating the table
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Apr 2010
    Posts
    2
    i try
    SELECT * FROM table_name WHERE "USER"= 'ABC'
    and it works.

    Thank you.

  5. #5
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    Always better to avoid reserved-words as column names though, SQL can be complicated enough "as-is".

Posting Permissions

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