Link to home
Start Free TrialLog in
Avatar of se_1581
se_1581

asked on

DB2 LOCATE & SUBSTR

Hi,

I'm trying to extract the state from the address fields. the format is this: street, ST where street is the name of the street and ST is the state initials from 2 letters. most of the time the following code works but there are instances where it returns the 2 letters starting with the second position.

code: select substr(column, locate(',','column')+2,2) from table

example where it doesn't work. Sturgis, MI . for this example it returns the string 'tu'

Any idea why is acting like this?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of se_1581
se_1581

ASKER

It worked great, the quotation was the problem.

Thanks,

Stelian