add query for cases to insert and update