There are two tables, the Existing Pay/Bill Table and the EditHistoryPlacement Table, that I wish to join together using the PlacementID column in order to generate the data in the EXPECT Existing Pay/Bill Table. I'm considering the use of the RANK function (with dateAdded… as a parameter) and the PARTITION clause (with PlacementID) on the EditHistoryPlacement Table. Once Rank and Partition are established, my plan is to use a CASE statement. This statement will compare the rank and dateAdded to the PeriodEndDate, allowing me to populate the PONumber… column accordingly.
Rules populate the PONumber column: (Let's use PlacementID 1234 as an example)
- If Rank equals 1 and based on the dateAdded.. column, look for dates in the PeriodEndDate column that are less than the date in dateAdded… Then, fill the PONumber_atPeriodEndDate column with the value from the oldValue column.
- If Rank equals 2, apply the same rule as in Rule 1 and fill the PONumber_atPeriodEndDate column with the value from the newValue column for the PeriodEndDate column that is greater than the date in dateAdded…
- If dateAdded equal to PONumber_atPeriodEndDate then populate the PONumber_atPeriodEndDate column with the value from the newValue column.
I hope the data below and the above explanation are helpful. Honestly, I don't know how this is going to work. I've been playing around with the ETL, but ranking the data in the EditHistoryPlacement Table is the furthest I've gotten. I would appreciate it if anyone could help.