Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:07:16+00:00 2026-06-07T17:07:16+00:00

I have to compare data between two table and check for any conflicts. Below

  • 0

I have to compare data between two table and check for any conflicts.

Below is sample data for two table Events & Bookings I need to compare bookings Table with Events Table based on Date & Time & show records which are in conflict.

Actually user can change event date & time once date is change user need to generate report that will show them if they already had any booking for that particular date & time-slot.

I am using following query to check if we have any booking for the updated events

Query

Declare @bTime varchar(10) = '10:30';
Declare @bDate date = '2012-08-15';
SELECT * FROM  EventDatesReporting   WHERE 
((CONVERT(time(0), EventStartTime) <= CONVERT(time(0),@bTime )  
    AND CONVERT(time(0), EventEndTime) >= CONVERT(time(0),@bTime ))
OR 
(CONVERT(time(0), EventStartTime) <= DATEADD(minute,59,CONVERT(time(0), @bTime))   
    AND CONVERT(time(0), EventEndTime) >= DATEADD(minute,59,CONVERT(time(0), @bTime))))
AND EventDates = @bDate

Above query works fine but i need to convert this query so that i can compare Booking table BookingDate & Time with Events Table I am looking for performance based ms sql-query as data in these tables can grow with time.

Events

EventID EventStartDate  EventEndDate    EventDates  DT        EventStartTime    EventEndTime
17      2012-07-25      2012-07-26      2012-07-25  2012-07-25  10:00:00        12:00:00
17      2012-07-25      2012-07-26      2012-07-26  2012-07-26  10:00:00        12:00:00
21      2012-05-28      2012-05-28      2012-05-28  2012-05-28  18:00:00        19:00:00
26      2012-01-01      2015-01-01      2012-07-01  2012-07-01  08:00:00        18:00:00

Bookings

BookingID   TotalVisitors   BookingDate Time    BookingCancelled
1900221519  5               2012-07-10  10:30   0
5600515751  1               2012-07-20  10:30   0
8044913913  41              2012-07-05  10:30   0
1638934678  5               2012-07-20  10:30   1
5685687635  9               2012-07-25  10:30   0

In theabove case we assume user has change the date of first event to 2012-07-25 which now conflicts with the booking table as we have booking for this date. We need to find such rows so that users can take action accordingly such as intimate user about their booking cancellation & so on.

Scenario & Details

Let me give you a complete picture we allow tour of let us say private museum from Monday – Friday at two different times one at 10:30 am and second one at 04:30PM and for each tour we can take maximum of 50 Visitor (People). Suppose a group of 50 wants to visit museum on 2012-08-15 at 10:30am then we will block this date on front end.
Frond end which is a simple web form with common fields like Name, Address, Company Name, No Of Visitors, Time (Which is a dropdown with two entries 10:30am,04:30pm) and Date of Visit (which is a calendar control that blocks the dates which has reached the full booking & will allow them to chose only those dates which are available.

On the other side Museum also organizes special event and they can block those dates on the booking form. Suppose an event which was scheduled for 2012-08-10 at 9:00am – 1:00pm & this date was blocked earlier by the admin. Now the date of event has changed to 2012-08-25. Since no event was scheduled for this date earlier so museum had some bookings for this date.

Since Museum can’t take any tours for people who have made booking for the same date 2012-08-25 needs to be informed. For this I need to compare the two table events table & booking table and find if we have any booking for 2012-08-25 at 10:30 if yes then we need to intimate the visitors by email about cancellation of their tours .

In my query I am also adding 59 minutes to time as we need to have a break of at least 1hour between EventStartTime or EventEndTime.

I hope this will give an idea of what kind of data I am looking for the report.
Query which I have mentioned works fine but I need to pass value of date & time from booking table to events table for each row in booking table & show only those records from Booking table which clash with eventDate & time

Desired Output
From the sample data I need a query which will show me following record only as if it conflicts with the booking after event date was changed

EventID BookingID   TotalVisitors   BookingDate Time    BookingCancelled
17      5685687635  9               2012-07-25  10:30   0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:07:18+00:00Added an answer on June 7, 2026 at 5:07 pm

    Assuming +1 hour actually means that a visit to museum lasts one hour, and this one hour must not be overlapped by some other museum activity, here is a query that finds such collisions. It is a simple join between two tables on date of booking/event, for booking that are not cancelled. Ovelapping interval is checked using expression explained here; essentially, two ranges overlap in start date of range A is before end date of range B AND end date of range A is after start date of range B. After and before might read after or equals or before or equals, depending how you define overlap.

    select e.EventID,
           b.BookingID,
           b.TotalVisitors,
           b.BookingDate,
           b.Time,
           b.BookingCancelled
      from EventDatesReporting e
     inner join Bookings b
       -- On same date
        on e.EventDates = b.BookingDate
       -- Overlapping intervals
       and e.EventEndTime >= cast(b.Time as Time)
       and e.EventStartTime < dateadd (hour, 1, cast(b.Time as Time))
       -- Only if booking is not cancelled
       and b.BookingCancelled = 'false'
    

    There is convenient SQL site called Sql Fiddle. I have put your sample and my answer there so you can check it online.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to check the differences between two html pages: One is an old
I am looking for a tool/command which can compare data between two PostgreSQL databases.
I've got two tables, and I want to compare the data between them, and
I have several sheets of data that have formulas written to compare values between
I wanted to compare 2 XMLs, which have the same data but the tag
I have to compare two strings for case insensitive equality which one is faster
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have two small data frames, this_tx and last_tx . They are, in every
I have two data files in tab separated CSV format. The files are in
I am trying to compare two byte arrays in memory and produce a data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.