CASE statement available?

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
landaghaar
Participant
Posts: 38
Joined: Wed Sep 19, 2007 10:11 am
Location: Canada

CASE statement available?

Post by landaghaar »

Is there any way to use in a Transformer Expression to handle multiple replace statements?

Just like CASE statement in programming or even in databases:

CASE param:
When 'A' Then 1
When 'Y' Then 2
When 'X' Then 3
When 'M' Then 4
....
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Not case, but you can have multiple if-then-else statements.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
landaghaar
Participant
Posts: 38
Joined: Wed Sep 19, 2007 10:11 am
Location: Canada

Post by landaghaar »

That sux.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

landaghaar wrote:That sux.
The if-then-else might, but not if you used Ereplace function.
gateleys
landaghaar
Participant
Posts: 38
Joined: Wed Sep 19, 2007 10:11 am
Location: Canada

Post by landaghaar »

gateleys wrote:
landaghaar wrote:That sux.
The if-then-else might, but not if you used Ereplace function.
How would you use that? Ereplace can only replace one string, how can you make it work like DECODE function in oracle or CASE statement in programming?
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: CASE statement available?

Post by gateleys »

landaghaar wrote:Is there any way to use in a Transformer Expression to handle multiple replace statements?

Just like CASE statement in programming or even in databases:

CASE param:
When 'A' Then 1
When 'Y' Then 2
When 'X' Then 3
When 'M' Then 4
....
For the exact problem, you could use -

Code: Select all

ereplace(ereplace(ereplace(ereplace(Arg1,'A',1),'Y',2),'X',3),'M',4)
Note that the function replaces every occurrence of the characters to their respective target values. So, if you have 'ABC', it will convert it to 1BC, and 'AYX' will convert to 123.
gateleys
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If it's character-by-character the most efficient function is Convert().

Convert("AYXM","1234",InLink.TheChar)

You might then need to convert to integer of some kind.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply