separated the sql statements in replace_loc