Hi,
Could you simplify this to a single statement. Something like:
set result = (select sum(reading)
from outputcsv
where (SEMColumn, Extension) IN (SELECT busno, qry
from SEMQueries
where busno = 1 ))
I'm not sure if MySQL is capable of doing multicolumn IN clause but you could try.
Also instead of literal values try to use bind variables for busno condition unless it's really a constant.