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 > DB2 leading zeros Trim/truncating

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-10, 22:55
HanNew2DB2 HanNew2DB2 is offline
Registered User
 
Join Date: Sep 2010
Posts: 17
DB2 leading zeros Trim/truncating

DB2 Ver9.1 on Windows o/s.

i have a column which stores member id's... in the database, values are stored as 0000088811, but on the front end app, the value for member id is only 5 digits(which may have zero - ex: 01234 as member id). question is of the 10 digits stored for the column, i want to get last five digits and want to truncate/Trim the leading 5 zeros.
my query: select STRIP(col_name, L, '0') as alias_name from table_name followed by rest of the query..... - but the problem is its striping all leading zeros, but my 5-digit member id field can have zero as its first digit...
which function and whats the syntax to my issue?
Any help is greatly appreciated...
Note: I'm very new to DB2.....

Cheers
Han
Reply With Quote
  #2 (permalink)  
Old 09-22-10, 00:01
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Use the substring function:

substr(col_name,6,5)
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 09-22-10, 11:11
HanNew2DB2 HanNew2DB2 is offline
Registered User
 
Join Date: Sep 2010
Posts: 17
Thumbs up It works!

Thanks much, it works with a minor change substr(col_name,5,5)
Reply With Quote
  #4 (permalink)  
Old 09-22-10, 12:00
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Hmm. If the column is ten digits and you only want the last five, wouldn't that be digits 6-10 (start at 6, lenght of 5)?
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Tags
trim

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