Relocation of misplaced SQL statements