i got a tring variable used to make a query. in a particolar condition i have to modify the string adding the result of a query.
var query ="";
if(x==0)
{
query="Select Y from db.tab where Z<>x";
}
else if(x>0 && x <1000)
{
query="Select Y from db.tab wher Z=x";
}
// so far so good!!!
else if(x>1000)
{
var query2 = "Select bla bla bla"
executequery(query2, function(error, result)
{
var res=result
console.log(result);
var code0=[];
for (var i = 0; i<res.length; i++) {
let Tot1 = res[i].codicefiliale;
code0.push('codicefiliale='+Tot1+' ||');
}
var code1 = code0.join(" ");
var code2 = code1.toString();
var code3 = code2.slice(0, -2);
var code4 = code3;
var code5 = "Select bla bla bla and ("+code4+")";
SO FAR SO GOOD!!!!
query=code5;
}
}
//THIS is the problem, i can't update the var "query" located outside the "else if" like in the other two cases...