Find Overlapps in dates (1 Viewer)

soldat452002

Registered User.
Local time
Today, 08:08
Joined
Dec 4, 2012
Messages
50
Hello

So currently im working in migrating data from two Regions (East, West) same data fields but the date ranges (Eff, Exp) either could overlap or not. Im trying to build a query to identify overlapping dates and insert them in order (Oldest to Newest date). Any help would be appreciated it.

The desired result would be to Insert a record with oldest date prior to the next record with the newest date.

My current query.

  • [East].[Eff] >= [West].[Exp]
  • [East].[Exp] <= [West].[eff]
  • [East].[Affiliation_ID] = [West].[affiliation_ID]
  • [East].[ID] = [West].[ID]




IdWest.EffWest.ExpWest.CodeWest.Affiliation_IDEast.EffEast.ExpEast.CodeEast.Affiliation_ID
192677173/4/20201/1/2200TMUTUAL297151510/17/20193/3/2020COMPLETE2971515
192677173/4/20201/1/2200TMUTUAL29715153/4/20201/1/2200TMUTUAL2971515
1931329012/6/20191/1/2200COMPLETE297151511/27/20191/12/2020COMPLETE2971515
1931329012/6/20191/1/2200COMPLETE29715151/13/20201/1/2200TMUTUAL2971515
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:08
Joined
May 21, 2018
Messages
8,527
I do not understand what you want to do, it is not very clear. However there are four cases for overlapping that normally need to check
Code:
|---------------|A
      |--------------|B
Start of A <= Start of B and End of A <= End of B   

            |---------------|A
      |--------------|B
Start of A >= Start of B and End of A >= End of B  

     |-------|A
  |--------------|B
Start of A >= Start of B and End of A <= End of B  


 |--------------------|A
   |--------------|B
Start of A <= Start of B and End of A >= End of B
 

plog

Banishment Pending
Local time
Today, 10:08
Joined
May 11, 2011
Messages
11,643
First and foremost:

The desired result would be to Insert a record with oldest date prior to the next record with the newest date.

There is no order in a table. There is no first record, no last, no next, no 217th record. Order exists on data only in queries when you explicitly tell the query how to order the data.

To help you we need a bigger view of the issue. I suggest you post 2 sets of data:

A. Sample data from all tables. Include table and field names and enough data to cover all cases. Do not include any extranoeus fields. Just the fields we need to use or show in the end.

B. Expected results of A. Show us what data you expect to end up with after this query runs.

Again, 2 sets of data--what you are starting with and what you hope to end with.
 

Bullschmidt

Freelance DB Developer
Local time
Today, 10:08
Joined
May 9, 2019
Messages
40
It looks like West.Eff and West.Exp column data is switched. This assumes that West.Exp is supposed to be the newer date like East.Exp is to East.Eff.
 

Users who are viewing this thread

Top Bottom