replace local variable with query