I have two tables in SQL, Contract_Period and Payment_Period, both of which have an Employee Key and start/end dates amongst other columns. The dates are linked to a calendar dimension but simplified just as date fields for the purpose of this. The employee key can occur multiple times on each table, or not at all.
Contract_Period:
Contract_Period_Key (PK), Employee_Key, Contract_Start_Date, Contract_End_Date
Payment_Period:
Payment_Period_Key (PK), Employee_Key, Payment_Period_Start_Date, Payment_Period_End_Date
What I am trying to achieve is to look at the Payment_Period table and establish whether, at any point between the start and end dates, the employee was also under contract. It doesn't have to be for the whole period, there just needs to be at least 1 day which exists in both date ranges.
The output I'd like to achieve is something like:DaysInPeiod
Would really appreciate any help!
TIA.