Serious Bug With Variable Assignement

Hi, i am working on a site with Scriptcase and i have a serious bug with Variables.
I have this SQL Query in an app

SELECT 
    MONTO,
    SUCURSAL,
    FECHA
FROM 
    dbo.VENTA_DIARIA_POR_LOCAL
WHERE [sqlWHERE]

You can notice that the query has a Variable named sqlWHERE.

In the other hand i have this Script on the onScriptInit Event.

if ([FLAG] <> 1) {
    sc_reset_global ([sqlWHERE]);
    [FLAG] = 1;
    $DESDE = '01/01/2015';
    $HASTA = '31/01/2015';
    $SUCURSALES = '';
    $FILTRO = '';
    if (isset($_GET['BEGIN_DATE'])) {
        $DESDE =  $_GET['BEGIN_DATE'];
        if (isset($_GET['END_DATE'])) {
            $HASTA = $_GET['END_DATE'];
            $FILTRO = "FECHA ENTRE $DESDE Y $HASTA";
        }
    } else {
        $WHERE = "FECHA BETWEEN '$DESDE' AND '$HASTA'";
    }
    if (isset($_GET['sucursales'])) {
         $SUCURSALES = $_GET['sucursales'];
    }

    if (empty($SUCURSALES)) {
        $WHERE = " FECHA BETWEEN '$DESDE' AND '$HASTA'";
        $FILTRO = "Fecha entre $DESDE y $HASTA";
    } else {
        $SUCURSALES = "'".str_replace(',', "','", $SUCURSALES)."'";
        $WHERE = " FECHA BETWEEN '$DESDE' AND '$HASTA' AND SUCURSAL IN ($SUCURSALES)";
        $FILTRO = "Fecha entre $DESDE y $HASTA y Sucursal est? incluida en ($SUCURSALES)";
    } 

    [sqlWHERE] = $WHERE." AND EMPRESA = " .[usr_company];
    
    echo '<table cellspacing="0" cellpadding="0" align="center" valign="top">';
    echo '<tbody><tr><td>';
    echo '<div class="scAppDivMoldura" style="font-family:Open Sans,Arial,sans-serif;font-size:12px;">';
    echo $FILTRO;
    echo [sqlWHERE];
    echo '</div></td></tr></tbody></table>';
    echo '<div style="heigth=10px;"> </div></tr></td></table>';
    
    
} ELSE {
    [FLAG] = 0;
    [sqlWHERE] = '1=1';
}

As you can see, the variable is Setted with some parameters received by Get Method and Printed on the screen.

Now, the problem is that the variable is passed to the SQL Query with old values. See this Screenshot where you can notice that the variable value printed on the screen deffers from the one that is passed to the SQL Query.

[ATTACH=CONFIG]n64817[/ATTACH]

This problem have me Stucked with the site, please i need an urgent solution for this.
Thank you very much in advance.
Regards,

Maximiliano

Scriptcase Bug.jpg

Scriptcase Bug.jpg

AnyBody can check this?
Thank you very much.

Maximiliano

Did you try [SIZE=12px]$WHERE [/SIZE][SIZE=12px]= [/SIZE][SIZE=12px]"(FECHA BETWEEN ‘[/SIZE][SIZE=12px]$DESDE[/SIZE][SIZE=12px]’ AND ‘[/SIZE][SIZE=12px]$HASTA[/SIZE][SIZE=12px]’)"[/SIZE][SIZE=12px]; [/SIZE]and so on? So with ( … ) around the between statement?
Operator precence can be always overruled with ( )
http://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html

Thank you for your help rr. I try that but still the same, the Variable is not updated for the SQL query.
The Query is executed almost always with the last value of the variable, so if you want to have the new value you have to refresh twice, but sometimes that doesn’t work anyway.
I’m really, do you see anything wrong in my PHP script or the way i assign the variable, i would like to think that this is not a bug, but it seems to be.
Thank you very much again.
Regards,

Maximiliano

I dont have enough details. I know for sure that if you use BETWEEN that you should almost always surround it with ( ) just to avoid trouble since another operator may have precedence over the BETWEEN so my first guess was that that happened here… Specially since you have FECHA BETWEEN … AND … AND … which would make things weird without the ( )

Did you try to move your php code to onApplicationInit?

According to the doc, onApplicationInit “[SIZE=12px]Occurs once only when the application is loaded. Prior to the application running sql.”

If you set [[/SIZE]sqlWHERE] there it should be correctly populated when SC executes the app sql.

Edit -
Also, is [sqlWHERE] set as out?