Commissions.dbf Guests.dbf Emp Effective Commission Guest Date Emp (m/d/y) (m/d/y) ------------------------------ --------------------- 1 1/1/1 100 1 4/4/2 1 1 5/1/2 125 2 4/4/2 2 1 6/1/2 150 3 5/4/2 1 2 1/1/1 100 4 5/4/2 2 2 6/1/2 110 5 6/4/2 1 6 6/4/2 2I want to match each guest with the Commission due the Emp for that date.
desired cursor: Guest Date Emp Effective Commission ----------------------------------------------- 1 4/4/2 1 1/1/1 100 2 4/4/2 2 1/1/1 100 3 5/4/2 1 5/1/2 125 4 5/4/2 2 1/1/1 100 5 6/4/2 1 6/1/2 150 6 6/4/2 2 6/1/2 110In reality, the data is more complicated than this, but this represents what I need to do.
Here's how I do it for a given Guest.Date Get_Commissions(tdDate) Select ; Emp, max(Effective) as Eff_Date ; From Commissions ; Where Effective<=tdDate ; Group by Emp ; into cursor Temp NoFilter Select ; a.Emp, b.Effective, b.Commission ; From Temp a Join Commission b on Str(a.Emp)+Dtos(a.Eff_Date) = Str(b.Emp)+Dtos(b.Effective) ; into cursor Temp Select ; a.Guest, a.Date, a.Emp, b.Effective, b.Commission ; From Guests a Join Temp b on a.Emp = b.Emp ; into cursor Temp