tags:

views:

1071

answers:

3

This is data in TB_USER table

USER_USERID    
 --------------     
 A111           
 A9999          
 ADMIN          
 AHO            
 AHO2           
 AHO3           
 AHO4

...and schema of TB_USER table is

 COLUMN_NAME           DATA_TYPE  DATA_LENGTH  
 --------------------  ---------  ----------- 
 USER_USERID           VARCHAR    15

When I execute following SELECT statement:

 SELECT USER_USERID FROM TB_USER WHERE USER_USERID = 'ADMIN '

...and:

 SELECT USER_USERID FROM TB_USER WHERE USER_USERID = 'ADMIN'

DB2 retreive same output following

USER_USERID    
 -------------- 
 ADMIN

How to fix this problem?

A: 

Instead of

SELECT USER_USERID FROM TB_USER WHERE USER_USERID = 'ADMIN '

Use

SELECT USER_USERID FROM TB_USER WHERE USER_USERID like 'ADMIN '
Rakesh Juyal
+2  A: 
Michael Hvizdos
A: 

You should use the RTRIM or TRIM function.

SELECT USER_USERID FROM TB_USER WHERE RTRIM(USER_USERID) = 'ADMIN'
Michael Sharek