Transformation logic - need to grab substring

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

hemanthakumar
Participant
Posts: 34
Joined: Mon May 05, 2008 1:31 am

Transformation logic - need to grab substring

Post by hemanthakumar »

Hi,
i have following requirement.
If the value contains "-" then use the last three characters of the string else use the whole string.

ex: 1) customer_usa output is usa
2) india output is india.
Any one can help me to resolve for the same.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Index() would find the position of the "-" and then you conditionally substring off everthing after it. Or not.
-craig

"You can never have too many knives" -- Logan Nine Fingers
HariK
Participant
Posts: 68
Joined: Thu May 17, 2007 1:50 am

Re: Transormation logic

Post by HariK »

Assuming only one instance of '_' occurs and you need only last three characters.

If index(column_name,'_',1) > 0 Then right(column_name,3)
Else column_name
hemanthakumar
Participant
Posts: 34
Joined: Mon May 05, 2008 1:31 am

Post by hemanthakumar »

i applied the logic, but its giving wrong result.
Thanks for your response.
hemanthakumar
Participant
Posts: 34
Joined: Mon May 05, 2008 1:31 am

Post by hemanthakumar »

Hi,
i have following requirement.
If the value contains "-" then use the last three characters of the string else use the whole string.

ex: 1) customer-usa output is usa ( corrected the delimiter)
2) india output is india.
Any one can help me to resolve for the same.
HariK
Participant
Posts: 68
Joined: Thu May 17, 2007 1:50 am

Post by HariK »

All you have to do is to read posts by Craig or me to get the logic.
hemanthakumar
Participant
Posts: 34
Joined: Mon May 05, 2008 1:31 am

Post by hemanthakumar »

i used dcount and field functions. Its working fine :D
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

hemanthakumar wrote:i applied the logic, but its giving wrong result.
You'd have to show us how you "applied" it and what results you saw as it should have worked just fine. And, like most things, there are multiple solutions to most problems - dcount and field being one such example.
-craig

"You can never have too many knives" -- Logan Nine Fingers
arunkumarmm
Participant
Posts: 246
Joined: Mon Jun 30, 2008 3:22 am
Location: New York
Contact:

Post by arunkumarmm »

Or you can try

Code: Select all

 If Count(Column,'_') > 0 Then Column[3] Else Column
Arun
hemanthakumar
Participant
Posts: 34
Joined: Mon May 05, 2008 1:31 am

Post by hemanthakumar »

Thanks Arun, " If Count(Column,'-') > 0 Then Column[3] Else Column" is also working fine.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As would the Index() and Right() functions.
-craig

"You can never have too many knives" -- Logan Nine Fingers
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

arunkumarmm wrote:Or you can try

Code: Select all

 If Count(Column,'_') > 0 Then Column[3] Else Column
Hi Arun,

Can you please tell me what Column[3] does here exactly?
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

hemanthakumar wrote:i used dcount and field functions. Its working fine :D
Hemanth,

Can you please give the exact syntax you used?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

agpt wrote:Can you please tell me what Column[3] does here exactly?
Without the starting position, it starts from the end so that means to substring off the last 3 characters from the string.
-craig

"You can never have too many knives" -- Logan Nine Fingers
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

chulett wrote:
agpt wrote:Can you please tell me what Column[3] does here exactly?
Without the starting position, it starts from the end so that means to substring off the last 3 characters from t ...
Hi Chulett... Sorry I couldn't read your whole message but I think I got the answer to my question. Thanks a lot!!!!
Post Reply