Wobbel
August 26, 2022, 9:02am
1
Hello, i have a query where i want to filter the where clause based on a checkbox. To transform the array to a readable list in the query i use the selectedValues.join(', ') method. For one value this works, but as soon as i check multiple values this fails.
There are a lot of values to be checked, and they change a lot, so the solution provided here:
How can we change data on a widget by choosing options on a select widget and updating the where clause on the query?
does not work for me here.
The datasource is a MS sqlserver
Can anybody help me out?
SELECT
locatie,
“sdf potmaat”,
teelt,
uitgangsmateriaal,
leverancier
FROM stamgegevens.producten
WHERE locatie IN ({{CheckboxGroup1.selectedValues.toString()}});
dancia
August 26, 2022, 11:22am
2
@Wobbel Do you have Prepared Statements turned ON? If yes, can you try turning it off and see if the query works?
Wobbel
August 26, 2022, 11:31am
3
I have tried it, and the query then stops working. I get the following error:
Invalid column name ‘’
which is weird, because it is in the where clause of the query and not the select.
The query evaluated as followed:
SELECT
teelt_id,
locatie,
“sdf potmaat”,
teelt,
uitgangsmateriaal,
leverancier
FROM stamgegevens.producten
WHERE locatie IN (S4);
I think is should cast the resulting value to string, i have tried the String() function and the to_String() method, but it doesnt work.
dancia
August 26, 2022, 12:55pm
4
@Wobbel Could you also try the below code
WHERE locatie IN {{"'" + CheckboxGroup1.selectedValues.join("', '") + "'"}}
Wobbel
August 26, 2022, 12:56pm
5
After tinkering with it for a little, the following solution works,
WHERE locatie IN ({{“'” + CheckboxGroup1.selectedValues.join(“', '”) + “'”}});
Thanks a lot for pointing me in the right direction!
1 Like
Wobbel:
WHERE locatie IN
I tried this in a MS SQL and it does not work when Prepared Statement is enabled. No error messages, just no results are returned.
Amelia
September 20, 2022, 8:49pm
7
Can you share a screenshot of the query?
Here is the query:
If I disable ‘Use Prepared Statement’, I get the results I expect.
But when ‘Use Prepared Statement’ is enabled, here is what happens:
There are no errors, just an empty response.
Amelia
September 22, 2022, 5:56pm
9
This is a known bug. The IN
and ANY
clauses do not work with Use Prepared Statement turned ON
. You can track this bug here: [Bug]-[11200]:Unable to use IN or ANY clause with prepared statements turned on for MySQL · Issue #11259 · appsmithorg/appsmith · GitHub
In the meantime, the workaround is to turn Use Prepared Statement turned OFF
.
1 Like