case statment

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
times29
Premium Member
Premium Member
Posts: 202
Joined: Mon Sep 22, 2008 3:47 pm

case statment

Post by times29 »

Hi,
How can i put case logic in datastage i want to put below logic in datastage
(ID) || ':' ||
case
when (COUNTRY) in ('US','CA') then 'US'
when (COUNTRY) in ('IE','GB') then 'GB'
when (COUNTRY) in ('NZ','AU') then 'AU'
else (COUNTRY)
end ||':' ||
case
when (COUNTRY) in ('US','CA') then 'US'
when (COUNTRY) in ('IE','GB') then 'GB'
when (COUNTRY) in ('NZ','AU') then 'AU'
else (COUNTRY)
end as BUSINESS_KEY,
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Post by vivekgadwal »

Using If-Then-Else

Code: Select all

If COUNTRY = 'US' Or COUNTRY = 'CA'
Then
    ...
    ...
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
times29
Premium Member
Premium Member
Posts: 202
Joined: Mon Sep 22, 2008 3:47 pm

Post by times29 »

Can you put few more lines?
times29
Premium Member
Premium Member
Posts: 202
Joined: Mon Sep 22, 2008 3:47 pm

Post by times29 »

Can you put few more lines?
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Post by vivekgadwal »

Code: Select all

If COUNTRY = 'US' Or COUNTRY = 'CA'
Then 
       'US'
Else
       IF COUNTRY = 'IE' Or COUNTRY = 'GB'
       Then
              'GB'
       Else
              If ...
It can get pretty convoluted...this is a brute force attack on your question.
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Another way is to use the INDEX function. Something like

Code: Select all

if index('US,CA', in.COUNTRY, 1) > 0 
then 
'US'
else if index('IE,GB', in.COUNTRY, 1) > 0
THEN
'GB'
else if index('NZ,AU', in.COUNTRY, 1) > 0
THEN 'AU'
ELSE in.COUNTRY
Last edited by DSguru2B on Wed Apr 13, 2011 1:46 pm, edited 1 time in total.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
times29
Premium Member
Premium Member
Posts: 202
Joined: Mon Sep 22, 2008 3:47 pm

Post by times29 »

And what about other case so are you saying do in two different columns for same transformer and then use another tarnsformer to merge two case
stmt
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Do it in two different stage variables and just concatenate them.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Post by vivekgadwal »

DSGuru2B is right. That would make it simpler. What I was trying to say is you can concatenate the second if then else in the same derivation/stage variable or a different one - depending on how aesthetic you want to be :wink:
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
times29
Premium Member
Premium Member
Posts: 202
Joined: Mon Sep 22, 2008 3:47 pm

Post by times29 »

i just renew my membership looks like it takes some time i have to wait for dsguru comment then
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Post by vivekgadwal »

times29,

You can solve this in myriad ways. One of the ways is to place your case statements (2 of them) in two stage variables and then concatenate all that you want in another stage variable. Use this final variable in a derivation column of your choice. Otherwise, do it all in one stage variable or derivation, whichever suits your requirement.

DSGuru2B also mentioned the same. Hope this is detailed enough for you...
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
Post Reply