Six Stars

How to return multiple columns value with if condition

Hello all,

 

How to return multiple column values with if condition?

 

Currently I wrote like below and it is giving me error.

 

The logic is subscriber info is null then return SP_SERV_ID, SITE_A_ID AND SUB_ACCOUNT field values.

 

row1.SUBSCRIBER == null ? row1.SP_SERV_ID, row1.SITE_A_ID, row2.Sub_Account
: null

 

Any help is much appreciated. 

4 REPLIES
Thirteen Stars

Re: How to return multiple columns value with if condition

What exactly are you trying to do? It looks like you are trying to actually apply logic to returning a row based on a column values. This can be done using the filtering in a tMap component. Can you give a bit more information on this. There will be a way of doing this, but we need a bit more info.

Rilhia Solutions
Six Stars

Re: How to return multiple columns value with if condition

Hello,

 

Thanks for the response.

 

Here is what I am trying to achieve. 

 

row1.SUBSCRIBER == null ? row1.SP_SERV_ID ||
row1.SUBSCRIBER == null ? row1.SITE_A_ID ||
row1.SUBSCRIBER == null ? row2.Sub_Account
: null

 

When I tested this I get below error,

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 

 

Requirement:

If Subscriber is null then return serv_id, site_a_Id, sub_account 

else Null

 

Regards,
Deepak

Thirteen Stars TRF
Thirteen Stars

Re: How to return multiple columns value with if condition

Hi,

What do you want to do?

Do you want to concatenate SP_SERV_ID, SITE_A_ID and Sub_Account?

In this case, try this:

row1.SUBSCRIBER == null ? row1.SP_SERV_ID + row1.SITE_A_ID + row2.Sub_Account : null

TRF
Thirteen Stars

Re: How to return multiple columns value with if condition

Why can you not do this with a tMap using a filter on the output? Take a look here: https://community.talend.com/t5/custom/page/page-id/Condition-based-filters-w-tMap

 

The condition you have given needs to be thought out differently. You are essentially concatenating the logic for 3 columns in one condition. If you want this to apply to each of the columns independently, you will need to break down the condition into 3 conditions (one per column). I *think* filtering a tMap output will better suit your requirement though.

Rilhia Solutions