Page 1 of 1

firstname,middle name, lastname

Posted: Wed Sep 19, 2012 3:17 pm
by srivalli_b
Hi
my source is teradata and target is sequential file.

source data:
vekat raJU
VENKAT RAM Raju narayana

output:

firstname=venkat
secondname=raju
middle name=null

firstname=venkat
secondname=ramraju
middle name=narayana.

based on the delimeter(space) I have to divide into three parts. Some times middle name contains two spaces.


my code:

sv1---> field(col1,' ',1)---firstname.

sv2--->field(col1,' ',dcount(col1,' '))--> lastname


can you please let us know how to get middle name?

Posted: Wed Sep 19, 2012 4:40 pm
by Kryt0n
On the assumption that if there is a potential for multiple spaces in the middle

Field(x,' ', 2, DCount(x,' ')-2)

When there are only two fields you may need to do an if first as I'm not sure Field allows 0 for the number of fields.

Posted: Wed Sep 19, 2012 11:22 pm
by srivalli_b
Thanks kryton

If there are multiple spaces in first name,lastname can you plese let me know how to handle this.

Posted: Thu Sep 20, 2012 1:28 am
by ArndW
Try this solution with 2 stage variables:

svWorkString Trim(In.NameString)
svNumberOfSpaces dcount(svWorkString)

Out.FirstName = Field(svWorkString,' ',1)
Out.LastName = Field(svWorkString,' ',svNumberOfSpaces)
Out.MiddleNames = Field(svWorkstring,' ',2,svNumberOfSpaces-2)


If there are no middle name(s) the Out.MiddleNames will be empty. The code above makes no provisions for strings with just one name.

Posted: Thu Sep 20, 2012 5:30 am
by bhasds
Hi srivalli_b,
If there are multiple spaces in first name,lastname can you plese let me know how to handle this.
In the above scenario the compactwhitespace function should work fine....

Code: Select all

If Dcount(CompactWhiteSpace(Col1)," ") >2 Then Field(CompactWhiteSpace(Col1)," ",2,Dcount(CompactWhiteSpace(Col1)," ")-2) Else ""

Posted: Thu Sep 20, 2012 11:16 am
by srivalli_b
Thanks for your reply.

multiple spaces will occur either first name,last name,middle name.some times multiple spaces may be occur at a time in middle and first,last names.

I think your code will work where I will know particular names (middle or last or first) will occur multiple spaces.
Please help me

Posted: Thu Sep 20, 2012 11:31 am
by ArndW
I did answer the question, with my code the input "William Jefferson 'Bill' Clinton"

Would get separated into First name "Wiliam", last name "Clinton", middle name "Jefferson 'Bill'".

Posted: Thu Sep 20, 2012 12:47 pm
by bhasds
Hi Srivalli_b,

I have tried with the below input-

Code: Select all

vekat    raJU
VENKAT RAM   Raju   narayana
Jean    Claude    Van Damme

Code: Select all

Field(CompactWhiteSpace(src.col1)," ",1)     col1

If Dcount(CompactWhiteSpace(src.col1)," ") >2 Then Field(CompactWhiteSpace(src.col1)," ",2,Dcount(CompactWhiteSpace(src.col1)," ")-2) Else ""        col2


Field(CompactWhiteSpace(src.col1)," ", Dcount(CompactWhiteSpace(src.col1)," "))          col3
Please confirm whether the above occurances of spaces between the strings are same as you are getting.If not please specify.

Posted: Thu Sep 20, 2012 1:33 pm
by chulett
srivalli_b wrote:multiple spaces will occur either first name,last name,middle name.some times multiple spaces may be occur at a time in middle and first,last names.
People provided code because your original problem definition was finite - one word first name, one word last name with only the 'middle name' possible as multiple words.

If that is not the case, meaning any of the three 'pieces' could be multiple words (contain spaces) then there is no simple parsing solution. It requires intelligence to recognize what bits look like first names, which look like last names and which remaining bits must be the middle name... never mind all of the Mr/Mrs/Dr/Jr/Sr bits. You are now firmly in the territory that companies (including IBM) build and market expensive software applications to solve.

In my opinion, the best you could do is go back to your original position but knowing that it will be wrong at times and probably require manual intervention to correct.