Quick search and dynamic sql with sc_select_where

Hello,
I read some threads but I can not find a solution

Hello,

I put a dynamic where sql in my grids. When I do this and use quick search there comes this error:
Fehler beim Datenbankzugriff:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘where vertrag_reparatur_id > 0 and vertrag_id=1’ at line 1
select count(*) from vertrag_reparatur where (vertrag_reparatur_id like ‘%1%’ or vertrag_id in (1,2,3,4,5,6,7,8,9,10,11) or Versorgungsorte like ‘%1%’ or Versorgungszeitraum like ‘%1%’ or Kostenuebernahme_bei_Pauschale like ‘%1%’ or Kostenuebernahme_bei_Bestandskunden like ‘%1%’ or KV_notwendig like ‘%1%’ or VO_notwendig like ‘%1%’ or Besondere_Hinweise like ‘%1%’ or inaktiv like ‘%1%’ or Erstellt_von like ‘%1%’ or Geaendert_von like ‘%1%’)where vertrag_reparatur_id > 0 and vertrag_id=1

My dynamic sql looks like this:
if (isset([v_vertrag_id])){

sc_select_where(add) = “where VA.vertrag_artikel_id > 0 and VA.vertrag_id=[v_vertrag_id]”;

$Vertragname = setTitleContract( [v_vertrag_id]);
[title] = "Vertrag Artikel zu Vertrag: ".$Vertragname;
}
else
{
sc_select_where(add) = "where VA.vertrag_artikel_id > 0 ";
}

Nothing of my grids with search work with this. It seems scriptcase add two where clauses?
Can I ask the search and put it in a if clause?
for example like
if (sc_btn_???) {…

[TABLE]
[TR]
[TD]sc_select_where(add)[/TD]
[/TR]
[TR]
[TD] [TABLE]
[TR]
[TD]Is possible, during grid execution time to add a field/condition to the search WHERE clause.

Ex. 1: It adds the contente between the quotes (") in the grids select.
if (empty({sc_where_current}))
{
sc_select_where(add) = “where campoX > [global]”;
}
else
{
sc_select_where(add) = “AND campoX > [global_variable]”;
}[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[TABLE]
[TR]
[TD]Note: This command must be in the context of “process before the select”.[/TD]
[/TR]
[/TABLE]

Macro Scope [TABLE]
[TR]
[TD]Aplicaci?n Gr?fica[/TD]
[TD]Aplicaci?n Grid[/TD]
[/TR]
[TR]
[TD]onScriptInit[/TD]
[TD]onHeader
onScriptInit[/TD]
[/TR]
[/TABLE]

try your two WHERE clauses in the SQL OF THE GRID. SO MAKE SURE THEY WORK SEPERATED.

thank you for this solution

was there a problem with the syntax of one of your WHERE clauses?