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 > SUBSTR - need to calc the start position...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-09, 13:02
SouthernGent SouthernGent is offline
Registered User
 
Join Date: Aug 2009
Posts: 2
SUBSTR - need to calc the start position...

Hey,

I'm writing queries against DB2 v8.1.0.36.
db2level returns 'Instance "DB2" uses "32" bits and DB2 code release "SQL08010" with level identifier "01010106".

I have a 60 character column called "Class".
The values in "Class" are Basic, Advanced, Basic-EXT, Advanced-EXT.
I need to identify only those values that end with "-EXT".

I had thought that I could use SUBSTR but I'm not providing the correct syntax to identify the start position which needs to the the length - 2.

SUBSTR (Class, LENGTH(RTRIM(Class))-2,2)

It does process SUBSTR (Class, LENGTH(RTRIM(Class)),2) but I only get 'T' back.

Any ideas?

Many Thanks!
Reply With Quote
  #2 (permalink)  
Old 08-28-09, 13:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You are computing the length of the string after any trailing blanks have been removed, but you are not removing them from the base string. Try something like: substr(rtrim(class),length(rtrim(class))-2,2)

Andy
Reply With Quote
  #3 (permalink)  
Old 08-28-09, 13:28
rdutton rdutton is offline
Registered User
 
Join Date: Dec 2008
Posts: 76
If you only need to identify them why not use LIKE '%-EXT'
__________________
RD
Reply With Quote
  #4 (permalink)  
Old 08-28-09, 14:55
SouthernGent SouthernGent is offline
Registered User
 
Join Date: Aug 2009
Posts: 2
Done and DONE

Thanks to both of you for your advice. The LIKE '%-EXT%' got me what I needed.

Preesh.....
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