firstname,middle name, lastname

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
srivalli_b
Participant
Posts: 32
Joined: Tue Dec 20, 2011 8:03 am

firstname,middle name, lastname

Post 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?
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post 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.
srivalli_b
Participant
Posts: 32
Joined: Tue Dec 20, 2011 8:03 am

Post by srivalli_b »

Thanks kryton

If there are multiple spaces in first name,lastname can you plese let me know how to handle this.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
bhasds
Participant
Posts: 79
Joined: Thu May 27, 2010 1:49 am

Post 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 ""
srivalli_b
Participant
Posts: 32
Joined: Tue Dec 20, 2011 8:03 am

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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'".
bhasds
Participant
Posts: 79
Joined: Thu May 27, 2010 1:49 am

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply