cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

compare collection with lookup table

nusair
Deputy Chef I
Deputy Chef I

: Dynamic SQL Query with Keywords from Lookup Table in Workato

Current SQL Query:

SELECT * FROM ( SELECT *, TRIM( COALESCE( CASE WHEN LOWER(TRIM(formula_1)) LIKE '%payments%' THEN 'Payments' ELSE '' END || CASE WHEN LOWER(TRIM(formula_1)) LIKE '%services%' THEN '|Services' ELSE '' END || CASE WHEN LOWER(TRIM(formula_1)) LIKE '%vendor%' THEN '|Vendor' ELSE '' END, ' ' ) ) AS matched_keywords FROM netsuite_records ) AS subquery WHERE matched_keywords <> '';
 

In this query, the keywords (payments, services, etc.) and columns (formula_1, formula_2, etc.) are hardcoded. I want to replace this logic with a dynamic solution where:

  1. Fetches Keywords and Columns Dynamically: Keywords and corresponding columns (e.g., payments -> formula_1, services -> formula_1) come from a lookup table.
  2. Dynamic Query Construction: The query dynamically matches keywords from the lookup table with specified columns from the netsuite_records dataset.

For example:

Lookup Table Data:

Keyword Columns

paymentsformula_1
servicesformula_1
vendorformula_1

Expected Query Behavior:

The query should dynamically construct CASE conditions based on the lookup table data, such as:

 
CASE WHEN LOWER(TRIM(formula_1)) LIKE '%payments%' THEN '|Payments' ELSE '' END || CASE WHEN LOWER(TRIM(formula_1)) LIKE '%services%' THEN '|Services' ELSE '' END || CASE WHEN LOWER(TRIM(formula_1)) LIKE '%vendor%' THEN '|Vendor' ELSE '' END
 

Key Requirements:

  • Use the Lookup Table action in Workato to fetch the entire lookup table.
  • Dynamically construct the SQL query to match keywords with the specified columns.

Approach Options:

  1. Use the lookup table data to create a collection in Workato and query the collection.
  2. Avoid creating a collection and directly pass the lookup table data as input to the SQL query.
  3. use python snippet to get data  from the lookup_table and check the conditions with netsuit_records

What would be the best way to achieve this dynamic query construction in Workato? Any suggestions or best practices would be greatly appreciated.

0 REPLIES 0