-1

I am building a mobile web app with jquery mobile. I want to make a reservation. So the user enters a room, a begin dateTime and an end DateTime. Then it goes to a webservice function which queryies the database.

It is gonna check if there is already a reservation between the start dateTime and the end dateTime, the user entered. If there is it is gonna put them in a list.

Now in my javascript I gonna call this function with a ajax call. Here I am going to check if there is something in this list --> the room is not available, else --> the room is available.

But there is something wrong with my query. Could you help me figure it out?

SELECT * FROM ARTICLES_RESERVERING res
INNER JOIN ARTICLES_ZAAL roo ON res.ZAALID = roo.ID WHERE roo.ID = @ZAALID 
AND (res.DATUM_BEGIN >= @DATUM_EINDE OR res.DATUM_EINDE <= @DATUM_BEGIN)

Could anybody help?

Kind regards.

Steaphannn

Steaphann
  • 2,797
  • 6
  • 50
  • 109
  • Why mulltiple questions? http://stackoverflow.com/questions/10798664/check-availability-of-a-room-with-sql/10798758#10798758 Have you tried other queries there? – ejb_guy May 31 '12 at 07:24
  • There are same four question I can see in your profile for checking reservation between start and end date. – ejb_guy May 31 '12 at 07:29
  • I asked it several times because when I let it test the app by somebody else there were still some errors in it. – Steaphann May 31 '12 at 07:43

1 Answers1

0

The general algorithm for overlapping events is:

if ((eventA.startTime <= eventB.startTime && eventA.endTime > eventB.startTime) ||
    (eventA.startTime < eventB.endTime && eventA.endTime > eventB.startTime)) 
{
    // events overlap
}

Edit

Changed the last part of the second line to cover the case where eventA is during eventB. Note that event start and end must be in the correct chronological order.

RobG
  • 142,382
  • 31
  • 172
  • 209
  • This requires that `eventA` either starts before or ends after `eventB`. You miss the case where `eventA` starts after `eventB` and ends before it. – lanzz May 31 '12 at 07:04