Page 1 of 1

CASE statement available?

Posted: Mon Oct 29, 2007 9:16 am
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
....

Posted: Mon Oct 29, 2007 9:24 am
by DSguru2B
Not case, but you can have multiple if-then-else statements.

Posted: Mon Oct 29, 2007 9:34 am
by landaghaar
That sux.

Posted: Mon Oct 29, 2007 10:01 am
by gateleys
landaghaar wrote:That sux.
The if-then-else might, but not if you used Ereplace function.

Posted: Mon Oct 29, 2007 2:05 pm
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?

Re: CASE statement available?

Posted: Tue Oct 30, 2007 6:30 am
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.

Posted: Tue Oct 30, 2007 7:34 am
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.