Filtering by field label name

Hey I want to filter a table by the labelname or labelvalue that I select in the filter (could be just one or multiple). I tried getting gemini and ChatGPT to alter the sql statement for me (i have little coding knowledge) but the all didnt work. The Name for the component is {{ multiselect.1selectedlabels }}.

These were the solutions by Gemini & ChatGPT:

GEMINI:
WITH selected_indications AS (
SELECT unnest(:{{ multiselect1.selectedLabels }}) AS indication
)

SELECT *
FROM "Angebote"
JOIN "HanseMerkur" ON "Angebote".id = "HanseMerkur".angebote_id
WHERE
-- Check if multiselect is empty
CASE WHEN :{{ multiselect1.selectedLabels }} IS NULL OR array_length(:{{ multiselect1.selectedLabels }}) = 0 THEN
-- Execute original query if empty
TRUE
ELSE
-- Filter by indication if not empty
"HanseMerkur".indication IN (SELECT indication FROM selected_indications)
END
ORDER BY "HanseMerkur".id ASC;

ChatGPT:
DECLARE @sqlQuery NVARCHAR(MAX)

IF NOT EXISTS (SELECT * FROM {{ multiselect1.selectedLabels }})
BEGIN
-- Wenn das Array leer ist, führe die normale SQL-Anfrage aus
SET @sqlQuery = '
SELECT *
FROM "Angebote"
JOIN "HanseMerkur" ON "Angebote".id = "HanseMerkur".angebote_id
ORDER BY "HanseMerkur".id ASC;'
END
ELSE
BEGIN
-- Wenn das Array nicht leer ist, filtere nach den ausgewählten Labels
SET @sqlQuery = '
SELECT *
FROM "Angebote"
JOIN "HanseMerkur" ON "Angebote".id = "HanseMerkur".angebote_id
WHERE "HanseMerkur".indication IN (''' + STRING_AGG(QUOTENAME(value), ''',''') + ''')
ORDER BY "HanseMerkur".id ASC;'
END

-- Ausführen der dynamischen SQL-Anfrage
EXEC sp_executesql @sqlQuery

Since this is only one of the filters I want to add I'm unsure if this is the most effecient way to implement it but I currently have no other idea apart from maybe having a seperate filter query instead of it being in the regular table query.

As always any help is greatly appreciated <3

Hello! I'm not sure I understand the issue but you can probably use the table filters from retool instead of trying to modify the query.
Add an event handler to the text input and make that set filters in the table.

Hey @GuilhermeSilva I need to have filters in german so I cant use the filter componenent available. But if i can change the filters in the background that would work. I couldnt find a way to do that though

You should be able to change them programmatically with the table's setFilter() method:

[via table docs]

This way, wherever that Javascript code lives, you can access the Select component's value in German and use that with the method. (I haven't tried this, but I believe it should work.)

Note that this would be filtering post SQL query, so depending on your performance needs it might not be appropriate. But I take "in the background" to mean that it's okay to perform locally/in the client.

This way you'll also have control over the timing of the filtering (when to start, or any debouncing or throttling of user input, etc).