if then else issue

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

samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

if then else issue

Post by samsuf2002 »

i have small req i am doing a look up to a fileset to get col B on key col A , A
is a key field in driver tbl and lookup fileset, if the lookup fails then col B will be empty
then i need to see if col A = 'REQ' then col B shud be "Request" else "Deny".
my code :
If IsNull(col B) or trim(col B) = ' ' Then If col A = 'REQ' then col B= 'Request' else col B= 'Deny' else col B
which comes in transformer next to lookup stage , but in the out put iam getting nothing its empty.

Thanks in Advance
Last edited by samsuf2002 on Thu Jun 14, 2007 6:16 am, edited 1 time in total.
hi sam here
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Try putting Parentheses in your code.

If IsNull(col B) or trim(col A) = ' ' Then (If col A = 'REQ' then col B= 'Request' else col B= 'Deny') else col B


I am not sure if this is the problem. But you can try it.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

I even tried that but still it is not working.
hi sam here
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

If IsNull(col B) or trim(col A) = ' ' Then If col A = 'REQ' then col B= 'Request' else col B= 'Deny' else col B

Say you have two links one is the lookup link 'lu' and the other is the input link ip.

Try this code in the derivation of ColB in the output

Code: Select all

if(IsNull(lu.ColB)) then ( if(trim(ip.ColA)='REQ') then 'Request' else 'Deny') else lu.ColB
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Actually i am doing this in transformer so there is only input link not lookup,
hi sam here
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

sorry for the mistake.
Minhajuddin wrote:If IsNull(col B) or trim(col A) = ' ' Then If col A = 'REQ' then col B= 'Request' else col B= 'Deny' else col B

Code: Select all

if(IsNull(ip.ColB)) then ( if(trim(ip.ColA)='REQ') then 'Request' else 'Deny') else lu.ColB

In the code above just change the "lu" to "ip" and then try.

Try this ---
|
|
V

Code: Select all

if(IsNull(ip.ColB)) then ( if(trim(ip.ColA)='REQ') then 'Request' else 'Deny') else lu.ColB
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Minaj --I used your code but still iam getting only spaces, i checked the output i am getting from lookup stage, it returns 50 spaces since col B is char(50). i tried to remove spaces and put it as varchar but i am not getting it.
hi sam here
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

samsuf2002 wrote:Minaj --I used your code but still iam getting only spaces, i checked the output i am getting from lookup stage, it returns 50 spaces since col B is char(50). i tried to remove spaces and put it as varchar but i am not getting it.

What didn't you get?

Can you give us some more info about your requirement?
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

I should get Request else Deny in col B depending on value of Col A when the lookup fails. when the lookup fails Col B should be empty or null then i should check what is the value in Col A (which is a lookup key ) if it is REQ then i should get Request else Deny in col B.
hi sam here
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

One last try

Here you go


Say you have a link called 'ip' to the transformer.

Use this code in the derivation of ColB.

Code: Select all

If(IsNull(Trim(ColB)=0)) then  ip.ColB else If(Trim(ColA)='REQ') then 'Request' else 'Deny'
This thing should work.
If it doesn't please put the exact code you are using in the transformer.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
splayer
Charter Member
Charter Member
Posts: 502
Joined: Mon Apr 12, 2004 5:01 pm

Post by splayer »

samsuf2002, one think I see is that, when you are doing trim(col B), you should compare it to '' not ' '. Are you doing that? It seems like you are not.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Trim() can never generate "".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

Ray is right !! .

My output from lookup stage which doesnt matches the key is coming as 50 spaces i need to reduce it to one space,empty or null. How can i do that ?
hi sam here
SAMEENA
Participant
Posts: 31
Joined: Fri Aug 18, 2006 12:13 am
Location: INDIA

Post by SAMEENA »

Hi Sam,
Did you try reading the output as 'varchar'.I mean,did you try defining the column as 'varchar' in the output metadat of lookup itself?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Trim() will get you to a single space. Convert() can get to "".
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