sql for closed instances corrected