Skip to content
Advertisement

Need to identify overlapping dates

I need to find overlapping dates for a table. So the basic structure is ID, PFX, Start date, and end date. So where the PFX for a given ID is overlapping with another PFX for each ID.

I tried this and had no luck. https://www.sqlservercentral.com/forums/topic/how-to-extract-overlapping-date-ranges-from-a-table-of-date-ranges

The highlighted is what I would want to show as an overlap.

enter image description here

Added this for some clarification of expected result. Desired outcome would show the 3 rows would be overlapping.  The keys are the ID AND PFX.

Advertisement

Answer

Improving upon the answer by Gordon, Can you check the following

dbfiddle link. https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=11f4e9dc6bd96df6f0c8145df0b953a8

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement