Add end date to sorting SQL only when order is ASC