Replace Temp with Query: total charge calculation is now seperated from
the statement's while loop