Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

    Code:
    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:

    Code:
    {where_statement} = "result of some very complicated calculations";
    into onLoad event. Right?

    And then change the initiating SQL to this:

    Code:
    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?
    Using Ubuntu Linux 13.04 and SC Professional MySQL 7.1.last
    We need: good and complete documentation written in proper English

  • #2
    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

    Comment


    • #3
      yes, this works fine.
      Using Ubuntu Linux 13.04 and SC Professional MySQL 7.1.last
      We need: good and complete documentation written in proper English

      Comment

      Working...
      X