I am trying to find overlapping dates within 10-days of the FROM_DATE
for the same PERSON_ID
but that occurred under a different MANAGER_ID
OR SHIFT_ID
. This is missing a number of dates which would show because they all fall 10-days before an instance where there is a different MANAGER_ID
OR SHIFT_ID
.
I created a DAYS_TABLE
with the SET_DATE
(FROM_DATE
) and TEN_DAYS
, which is 10-days from the SET_DATE
.
SELECT DISTINCT
F.*
FROM #MAIN_TABLE F
INNER JOIN #DAYS_TABLE O
ON (F.PERSON_ID = O.PERSON_ID)
AND(F.ORDER_NBR != O.ORDER_NBR)
AND (NOT((F.MANAGER_ID = O.MANAGER_ID) OR
(F.SHIFT_ID = O.SHIFT_ID)))
WHERE (F.FROM_DATE BETWEEN O.SET_DATE AND O.TEN_DAYS
);
I expect to see all instances where there is a PERSON_ID
with date overlaps (10 days forward) for either a different SHIFT_ID
or different MANAGER_ID
. This would include all dates that maybe under the same SHIFT_ID
or MANAGER_ID
but fall within the 10-days where there is a difference.
PER_ID SHFT_ID MGR_ID FROM
1 A U1 1/1/2019
2 A U1 1/1/2019
1 A U2 1/12/2019
2 B U2 1/12/2019
1 B U3 1/11/2019
PER_ID SHFT_ID MGR_ID FROM 10_DAYS
1 A U2 1/12/2019 1/22/2019
1 B U3 1/11/2019 1/21/2019