Knowledge Drop

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

  • 15 June 2021
  • 0 replies
  • 263 views

Userlevel 1

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:

 

 

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.

 

 

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.


 

 

This content is subject to limited support.                

 

 

 


0 replies

Be the first to reply!

Reply