Seven Stars

I need to convert the below SQL case statement into if\else for talend

Hi Talend Folks,

i need your help. could you please tell me. how to convert the below SQL case statement into if\else using tmap components for talend.

 

(case
when
(case
when t1.Sales = 'others' and t2.Bundled = 'Bundled'
then 'Bundled'
else t1.Sales end) = 'others'
then 'Discounted'

else
(case
when t1.Sales = 'others' and t2.Bundled = 'Bundled'
then 'Bundled'
else t1.Sales end)
end) AS Bundle

4 REPLIES
Twelve Stars TRF
Twelve Stars

Re: I need to convert the below SQL case statement into if\else for talend

Can you share the flow schema?

Is only 1 flow or 2?

Also give a sample input data with expected result.


TRF
Seven Stars

Re: I need to convert the below SQL case statement into if\else for talend

My source is excel file. I have sql logic. i need to create same sql expression in talend using tmap.

Sales Excel and drop it to the design work space and select tfileInputExcel option from pop window then am using tmap component. I dragged all columns into output excel file side then I Just created new column as bundled then I wrote if \ else Statement. the logic is given below

 

((row8.Sales == "others" && row9.Bundled== "Bundled") ? "Bundled" : ((row8.Sales) == "others" ? "Discounted" :

((row8.Sales == "others" && row9.Bundled== "Bundled") ? "Bundled" :

((row8.Sales)))))

 

Above logic is not working. am getting error 

Twelve Stars TRF
Twelve Stars

Re: I need to convert the below SQL case statement into if\else for talend

1st, don't use "==" to compare strings, use String.equals method or String.equalsIgnoreCase instead giving:

"others".equals(row8.Sales)

and so on.

2nd, rethink the logic, you have twice the same test (row8.Sales == "others" && row9.Bundled == "Bundled") which cannot occurs.

 


TRF
Six Stars med
Six Stars

Re: I need to convert the below SQL case statement into if\else for talend

Hello,

 

You can use condition statement in tMap :

 

row1.myKey.equals("FirstValue")?1:0

 

which allow you to do your query in the variable window and get the result in the tMap output.

 

Thanks,

Med