Knowledge Drop

Dynamic Joins - How to use liquid to dynamically adjust sql_on conditions

Userlevel 5

Last tested: Oct 22, 2019

Define the different join conditions within liquid if/then control flow statements:

explore: order_items {

join: orders {

relationship: many_to_one

sql_on: {% if and orders.created_date._in_query %}

${} = ${order_items.order_id} AND ${orders.created_raw} = ${order_items.returned_raw}

{% elsif %}

${} = ${order_items.order_id}

{% elsif orders.created_date._in_query %}

${orders.created_raw} = ${order_items.returned_raw}

{% endif %}





In the above example, I am joining on A) the date and id fields if both the date and id field are included in the query, B) the id field if only the id field is included in the query, and C) the date field if only the date field is included in the query.


Note: Make sure to confirm your if statements are in the order you would like them evaluated because the process will return the "then" response for the first true logic test.


This content is subject to limited support.                



0 replies

Be the first to reply!