Page 1 of 1

Substring function when find a dash

Posted: Mon Nov 17, 2014 11:08 am
by sam334
All,
Have an issue with the substrng function in server job.

I three columns coming from several DB2 inputs. All having date, description and count. Like,
Date Count Customer_cd
11-10-2014 125 3- Marketing client

I need to have only 3 instead of 3- Marketing client. The code may change so cant use substr(1,1) rather need to find DASH and substring there.

Any help how to achieve this.

Thanks.

Posted: Mon Nov 17, 2014 11:14 am
by chulett
Use Index() to find the correct dash and then use the position it returns in your substring.

Posted: Mon Nov 17, 2014 3:45 pm
by ray.wurlod
One solution

Code: Select all

Oconv(Field(InLink.Customer_cd, " ", 1, 1), "MCN")

Posted: Mon Nov 17, 2014 10:03 pm
by sam334
Thanks Ray and Craig.. Appreciate your help. I tried both and both worked.

Posted: Tue Nov 18, 2014 9:42 am
by sam334
Just found one more thing, for only 3 - Marketing client or 4 - Human resource , both the codes were working fine.

Now we got different codes as well such as BA 100 - Outgoing call, CC 203 - Call center.

In this case, it is only picking up , BA and CC instead of BA 100.

Posted: Tue Nov 18, 2014 10:19 am
by chulett
Show us your input string, the derivation you are using, the output you are getting and what you want it to be.

Posted: Tue Nov 18, 2014 2:41 pm
by sam334
Craig,
Found the issue, Both index(),position and Ray's code were working fine. Issue was, there was an EM dash and dash between the description. Replaced the em dash with single dash and now it worked.

Posted: Tue Nov 18, 2014 2:43 pm
by chulett
8)