updated SQL for scheduler, needs to be updated later on!!