Quantcast
Channel: Ben Hamilton
Viewing all articles
Browse latest Browse all 173

Multiple ternary expressions

$
0
0

This is how to use Talend to concatenate multiple columns (fields) into one field neatly.

Say we have three fields, row1.field1, row1.field2, row1.field3 that we want to insert into a output.notes column.

In the tMap component, use the following expression”


(StringHandling.LEN(row1.field1) > 0 ? “Comment: ”+row1.field1+“ ” : "“)+(StringHandling.LEN(row1.field2) > 0 ? ”Comments “+row1.field2+” “ : ”“ )+(StringHandling.LEN(row1.field3) > 0 ? ”Vaction Address: “+tblStudent_c.VacAddress+”, “+tblStudent_c.VacSuburb+”, “+tblStudent_c.VacState+”, “+tblStudent_c.VacPcode+” “ : ”")

What this does is check to see if field1 has anything in it (i.e. has a length longer than 0), if it does, it adds the field and a space after it to buffer it against the next field. If it doesn’t, then it doesn’t insert anything. It then does the same for fields 2 and 3.


Viewing all articles
Browse latest Browse all 173

Trending Articles