1

I've been trying to figure this out for a while now and have not got any closer. I get the error:

An expression of non-boolean type specified in a context where a condition is expected, near 'or'.

My SQL query is:

SELECT Pitch.Location_id
FROM PITCH
WHERE (((Pitch.Location_Id) Not In 
(SELECT Location_Id FROM BOOKING
          WHERE BOOKING.StartDate or BOOKING.EndDate    
                 NOT BETWEEN '2014-06-08'  AND '2014-07-08')) AND    
((PITCH.Type_name)='Delux') AND ((PITCH.Available)=1))

If I remove the or BOOKING.EndDate, the query works perfectly.

1
  • your Q have an answer :), you have to keep seperate WHERE BOOKING.StartDate NOT BETWEEN '2014-06-08' AND '2014-07-08' or BOOKING.EndDate NOT BETWEEN '2014-06-08' AND '2014-07-08' Commented Aug 8, 2015 at 17:43

2 Answers 2

1

Try this (as @tinka suggested above):

SELECT Pitch.Location_id
FROM   PITCH
WHERE  ((Pitch.Location_Id) Not In   
          (SELECT Location_Id FROM BOOKING
           WHERE BOOKING.StartDate NOT BETWEEN '2014-06-08' AND '2014-07-08'
              OR BOOKING.EndDate   NOT BETWEEN '2014-06-08' AND '2014-07-08'))     
           AND   ((PITCH.Type_name)='Delux') AND ((PITCH.Available)=1))
Sign up to request clarification or add additional context in comments.

1 Comment

works a charm, ive put this into my php script now and getting issues :/ will post another question
0

This is the query you should try. Note that the inner query is still in sargable syntax.

SELECT P.Location_id FROM PITCH P
   WHERE 
     P.Type_name='Delux' AND 
     P.Available=1 AND
     P.Location_Id NOT IN 
      (
         SELECT Location_Id FROM BOOKING B
           WHERE 
             B.StartDate < '2014-06-08' OR 
             B.StartDate > '2014-07-08' OR 
             B.EndDate   < '2014-06-08' OR 
             B.EndDate   > '2014-07-08'
       )

Now the reason why you received that error was because

WHERE BOOKING.StartDate or BOOKING.EndDate NOT BETWEEN '2014-06-08' AND '2014-07-08'

is evaluated like Booking.Startdate being OR-ed with BOOKING.EndDate NOT BETWEEN '2014-06-08' AND '2014-07-08'. The latter yields a boolean result of true false but the former expression Booking.StartDate is not boolean.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.