Using assign | sql_quote filter value in an if statement in a derived table

Knowledge Drop

Last tested: Dec 22, 2020
 

The Problem

If using the liquid assign tag to assign a filters value to a liquid variable, and then using this variable in an if statement in a derived table; the if statement does not seem to be pointing to the correct one based on the filters value.

A Solution

You will need to wrap the value in double quotes, and if it is a string that will result in double and single quotes like so:

174ca196-30b4-4503-b3ea-42d2a0142664.png

In the above derived table you can see that we have  -- {{is_timezone_filter_quote}} in the top under our assigned. This prints the exact value of our assigned variable from the assign for the filter.

You can see here in the explores sql that the assigned fields value is actually 'Yes' , a Yes wrapped in single quote all of which is a string value, so then we need to use "'Yes'" in the if statement to define this as the string value including the single quotes.

66f55429-98c2-44e8-8362-71b2e4b937ac.png

Just to note: If using the _filter reference directly in the if statement and NOT using assign though, you don’t need to double wrap as you can see here it points to A correctly. As it has a value of Yes  in the first if statement, the filter Yes is true since Yes = Yes.

b2e1c3b4-5675-4263-8a85-1031daa1b9ef.png


 

84e180a2-bb51-4ff5-bc2c-1c6ceaab8afa.png

This content is subject to limited support.                

Version history
Last update:
‎06-14-2021 06:16 PM
Updated by: