INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Extract part of a field using MID

Extract part of a field using MID

(OP)
Hi,
I'm trying to extract a portion of a field. The fields value might be "0123456-PO-555556666 SOMETEXT OR NUMBERS" .
I just want to extract the PO number portion, which would be 555556666. I've been playing with a MID({TABLE.FIELD},InStr({TABLE.FIELD},'PO-')+3) formula, which seems to work to exclude the 0123456-PO- portion which is great. I'm still struggling on how to remove the stuff after the 555556666 (need to eliminate the space and the SOMETEXT OR NUMBERS. Any ideas on how to do that in one formula?

RE: Extract part of a field using MID

seems like you encase the above formula in a left function (i.e., LEFT( MID({TABLE.FIELD},InStr({TABLE.FIELD},'PO-')+3), INSTR(MID({TABLE.FIELD},InStr({TABLE.FIELD},'PO-')+3), ' ') -1) ). This has not been tested.

RE: Extract part of a field using MID

Just for another approach, you could use a loop if the first character after the PO number is always non numeric (and the actual PO number is always numeric):

whileprintingrecords;
stringvar v_text := MID({YourField},InStr({YourField},'PO-')+3) ;
stringvar v_PO;
numbervar x := 1;
while isnumeric(v_text[x])
do
(v_PO := v_PO + v_text[x];
x := x + 1);

v_PO

RE: Extract part of a field using MID

Or as long as the PO number is always numerical, you could use:

CODE

VAL(MID({TABLE.FIELD},InStr({TABLE.FIELD},'PO-')+3)) 


I'm guessing the length of the PO number isn't consistent, but if it is always 9 characters long you could use:

CODE

MID({TABLE.FIELD},InStr({TABLE.FIELD},'PO-')+3, 9) 

Cheers
Pete

RE: Extract part of a field using MID

If it always looks like nnn-PO-nnnn then you can use split.

Split({table.field},"-",3) will turn the field into an array of three elements, and return the third one.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close