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

Eight Stars RAJ
Eight 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

Thanks
RAJ
Fifteen Stars TRF
Fifteen 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
Eight Stars RAJ
Eight 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 

Thanks
RAJ
Fifteen Stars TRF
Fifteen 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
Seven Stars med
Seven 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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads