Category: Appsmith Support
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Need two equality condition IS NULL and appsmith.store?.variable in a single where clause in mysql

Issue

I am trying to write a MySQL query in Appsmith that checks for an equality condition with the appsmith parameter, but I need to use both the "Use Prepared Statement" toggle on and off in the same query. Specifically, I need to check for a column value that is null, which requires the "Use Prepared Statement" toggle to be off. Adding quotes around the storeValue condition seems to have solved the issue.

Resolution

The user was trying to write a MySQL query that checks for an equality condition with the appsmith parameter - appsmith.store.currentStateName in the WHERE clause, where currentStateName is set in a javacript function. The query required the "Use Prepared Statement" toggle to be set as ON, but also needed to check for a NULL condition in a column value which requires the "Use Prepared Statement" toggle to be set as OFF. To achieve both conditions in a single query in Appsmith, the solution was to put the storeValue condition in quotes and to try turning off the Use Prepared Statement option if the quotes did not work.

The final working query looked like this:

select * from table WHERE field1.CurrentState = '{{ appsmith.store?.currentStateName}}' AND field2 IS NULL