ikke sikker på, hvordan dette vil fungere i forhold til et større datasæt, men det får de rigtige resultater for det angivne datasæt. Manglende datapunkter antages at være tilgængelige.
declare @startDate datetime, @endDate datetime, @days int
select @startDate = '6/1/2013', @endDate='6/3/2013', @days=2
select trainer, min(date)
from
(
select trainer,date,
(select top 1 date
from mySchedule sInner
where sInner.date > sOuter.date
and sInner.trainer = sOuter.trainer
and sInner.Dirty = 1
and sInner.date between @startDate and @endDate
order by sInner.date) as nextDirtyDate
from mySchedule sOuter
where sOuter.dirty=0
and sOuter.date between @startDate and @endDate
) sub
group by trainer, nextDirtyDate
having dateDiff(d, min(date), isNull(nextDirtyDate,dateAdd(d,1,@endDate))) >= @days