i am attempting to write a query as part of a music school which will select only tutors which are available at a certain time on a given day, lessons can be booked in blocks of ten twenty or thirty and as such i need to check either 10, 20 or 30 weeks to see if the lesson wanted is free on all of the corresponding days, the query i am currently using is not allowing lessons within the time period but should be allowing them on any day of the week except the one booked, i hope that is coherent
select Tutor.TutorId
from Tutor
left Join Booking on Tutor.TutorId=Booking.TutorId
where Tutor.Instrument='Keyboard'
and Booking.StartTime!='13:00:00'
and '2017-03-16' NOT between Booking.StartDate and DATEADD(dd,70, Booking.StartDate)
and ABS((DATEDIFF(DD,'2017-03-16',Booking.StartDate)))%7 =0
or
Booking.StartTime is null
and Tutor.Instrument='Keyboard'
or
Booking.StartDate NOT between '2017-03-16' and DATEADD(dd,70, '2017-03-16')
and Tutor.Instrument='Keyboard'
and ABS((DATEDIFF(DD,'2017-03-16',Booking.StartDate)))%7 =0