If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Reserved Word Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-10, 03:53
keanhoo168 keanhoo168 is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
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'?
Reply With Quote
  #2 (permalink)  
Old 04-14-10, 04:25
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Try this:
Code:
SELECT * FROM table_name WHERE "user"= 'ABC';
Reply With Quote
  #3 (permalink)  
Old 04-14-10, 04:42
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #4 (permalink)  
Old 04-14-10, 21:35
keanhoo168 keanhoo168 is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
i try
SELECT * FROM table_name WHERE "USER"= 'ABC'
and it works.

Thank you.
Reply With Quote
  #5 (permalink)  
Old 04-15-10, 01:44
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Always better to avoid reserved-words as column names though, SQL can be complicated enough "as-is".
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On