Hi all,
I am trying to write multi query and execute SET variables and than use them in next query. I am not sure if this is correct way for using with reports and binding. I know this isn't package related topic.
function setup()
{
$this->src('automaker')
->query("SET @DatumOD:=:start")
->query("SET @DatumDO:=:end")
->query("SET @Ukupno:= 0")
->query("select @Ukupno:=SUM(Kolicina) as Ukupno from my_table where DispatchDate between @DatumOD and @DatumDO")
->query("select NazivDobavljaca, sum(Kolicina) as Kolicina, (SUM(Kolicina))/(@Ukupno/100) as Procenat from my_table where DispatchDate between :start and :end")
->params(array(
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
))
->pipe($this->dataStore("my_data_store"));
}
I m trying to set ->query("SET @Ukupno:= 0") and with next step get calculated value which will be used in last query statement. In this case, (SUM(Kolicina))/(@Ukupno/100) as Procenat - @Ukupno isn't accessed and calculation it wrong. This example above does not throw any errors, only column "Procenat" does not have any data in DataTables table.
Can someone point me in right direction pls.