Finding first alphabetic character in a DB2 database field

Posted by Paul Alan Taylor on Stack Overflow See other posts from Stack Overflow or by Paul Alan Taylor
Published on 2010-04-29T12:53:10Z Indexed on 2010/04/29 12:57 UTC
Read the original article Hit count: 591

Filed under:
|
|

I'm doing a bit of work which requires me to truncate DB2 character-based fields. Essentially, I need to discard all text which is found at or after the first alphabetic character.

e.g.

102048994BLAHBLAHBLAH

becomes:-

102048994

In SQL Server, this would be a doddle - PATINDEX would swoop in and save the day. Much celebration would ensue.

My problem is that I need to do this in DB2. Worse, the result needs to be used in a join query, also in DB2. I can't find an easy way to do this. Is there a PATINDEX equivalent in DB2?

Is there another way to solve this problem?

If need be, I'll hardcode 26 chained LOCATE functions to get my result, but if there is a better way, I am all ears.

© Stack Overflow or respective owner

Related posts about db2

Related posts about patindex