I am struggling with the appropriate query to find duplicates while at the same time respecting the effective start and end dates for the record. Example data below.
ClientName ClientID EffectiveStart EffectiveEnd A 1 1900-01-01 2100-01-01 A 1 1900-01-01 2100-01-01 B 2 1900-01-01 2012-05-01 C 2 2012-05-01 2100-01-01 D 3 1900-01-01 2012-05-01 E 3 2012-04-30 2100-01-01 F 4 2012-04-15 2100-01-01
The output I am looking for is below.
ClientName ClientID A 1 D 3 E 3
The logic is that Client A has ID 1 duplicated. Client B and C have a duplicate (2) BUT the date ranges are such that the two duplicates DO NOT overlap each other, which means they should not be considered duplicates. Client D and E have ID 3 duplicated AND the date ranges overlap so it should be considered a duplicate. Client F does not have a duplicate so should not show in the output.
Any thoughts? Questions?