SC7.1 how to change dynamically WHERE condition in the main SQL (in SQL settings)

I want (in a grib and in a form app) to change the main SQL statement - but only WHERE condition.

So let’s imagine the grid app with main SQL statement (in SQL settings) like this:

SELECT
  column1,
  column2
FROM
  sometable

This is like always.

But then I want to add a condition WHERE.
But I want the condition to be calculated in the same aplication.
So logical would be put a code like this:

{where_statement} = "result of some very complicated calculations";

into onLoad event. Right?

And then change the initiating SQL to this:

SELECT
  column1,
  column2
FROM
  sometable
WHERE {where_statement}

On some reason SC erase all local vars and nothing goes through so the SQL gives error.

I’ve checked and Global variable would work if was set up before eg. in other app but I don’t like that idea - it’s not elegant and leads to producing many unnecesarry blank or control apps.

Is there a way to archieve my goal?

Hi,
your initial idea is correct and it has to be a global variable.
The variable has to be set before the execution of the SQL statement, which is onApplicationInit or onScriptInit.

So your select statement looks like:

SELECT
column1,
column2
FROM
sometable
WHERE [glo_where]

And in i.e. onScriptInit do all your fancy stuff

[glo_where] = “result of some very complicated calculations”;

jsb

yes, this works fine.