I have two tables that feed a view. The main table provides a date range to indicate eligibility for a benefit. The override table indicates that their option type is different based on a different date range.
Main Table
MemberId | OptionId | OptionType | StartDate | EndDate |
---|---|---|---|---|
000012345 | 123456789 | Type1 | 1/1/2023 | 12/31/2023 |
Override Table
MemberId | OptionId | OptionType | StartDate | EndDate |
---|---|---|---|---|
000012345 | 123456789 | Type2 | 11/1/2023 | 11/30/2023 |
In the example tables, the override table indicates that the member has a non-standard benefit during the override period. This means that the view feeding from these tables needs to show 3 separate records like:
View
MemberId | OptionId | OptionType | StartDate | EndDate |
---|---|---|---|---|
000012345 | 123456789 | Type1 | 1/1/2023 | 10/31/2023 |
000012345 | 123456789 | Type2 | 11/1/2023 | 11/30/2023 |
000012345 | 123456789 | Type1 | 12/1/2023 | 12/31/2023 |
How do I achieve this efficiently?
I have tried looping through the records to populate a separate temp table using while loops and/or cursors but it runs for a very long time. This view feeds a private member facing website that needs to populate immediately.