I didnt write the SQL for this one as i think it is pretty similar to work done recently by DevOps. I have given enough info below to clarify what needs doing though i think.