Hi all,
I have two different data tables, and I need to find and select if the word exist on the other table.
I tried using Contains() but is not working. Please help
Here is an example:
dt1
dt2
| dog&gorilla |
| mouse, giraffe |
| shark, whale, penguin |
| ostrich&bird |
| lion&tiger,cow |
Result (text in bold characters are selected):
dt2
| dog&gorilla |
| mouse, giraffe |
| shark, whale, penguin |
| ostrich&bird |
| lion&tiger,cow |
Here is one way to do what you are looking for. Please note, I believe your table that shows the results has row 3 incorrectly selected.
Names Default To Here( 1 );
// Create the tables
dt1 = New Table( "Lookup", Add Rows( 5 ), New Column( "key", Character, Set Values( {"dog", "cat", "fish", "bird", "cow"} ) ) );
dt2 = New Table( "Base",
Add Rows( 5 ),
New Column( "Target", Character, Set Values( {"dog&gorilla", "mouse, giraffe", "shark, whale, penguin", "ostrich&bird", "lion&tiger,cow"} ) )
);
// Place all key values into a list
KeyList = dt1:key << get values;
// Loop across the keys and search each row of Target for the
// match
For Each( {val}, keyList,
For Each Row(
If( Contains( :Target, val ),
Row State( Row() ) = Selected State( 1 )
)
)
);

Just a follow up question, can I use this selected rows in matching to other tables? Like in Update?
I am not understand your question. However, you can easily create a subset of the base table that contains just the selected rows, and then you can update another table from that table. Here is the JSL to do the subsetting
dt3 = dt2 << Subset( selected columns( 0 ), selected rows( 1 ) );