I am stuck with the following WITH part. When there are no results when the startdate and enddate condition is not met the query takes a very long time and eventually return