PresidentLincoln
asked on
DB2: Need to extract last 3 characters of a string
I need to extract a set of numbers from a string in a DB2 query. The string length will vary, but the numbers I will need to extract will always be the last 3 numbers, and they will always follow the same text pattern. For example, I have a string that looks like this:
The "CustomerNumber" itself could be anywhere from 3 to 20 numbers (5555555 in this case), but the "IndividualCode" will always be 3 numbers (999 in this case), and will always be preceded by the pipe and the string "IndividualNumber=".
So I need to be able to write a SELECT query in DB2 that will just give me the last 3 numbers of that entire string. I might have given too much info here to say "how do I always extract the last 3 numbers of this string", but I wanted to err on the side of caution.
Just FYI, I am using an AIX database and IBM Data Studio 4.1.3.
CustomerNumber=5555555|IndividualNumber=999
The "CustomerNumber" itself could be anywhere from 3 to 20 numbers (5555555 in this case), but the "IndividualCode" will always be 3 numbers (999 in this case), and will always be preceded by the pipe and the string "IndividualNumber=".
So I need to be able to write a SELECT query in DB2 that will just give me the last 3 numbers of that entire string. I might have given too much info here to say "how do I always extract the last 3 numbers of this string", but I wanted to err on the side of caution.
Just FYI, I am using an AIX database and IBM Data Studio 4.1.3.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER