Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL help
Message
From
18/07/2002 15:25:49
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
SQL help
Miscellaneous
Thread ID:
00680170
Message ID:
00680170
Views:
65
I'm using VFP7 SP1.

Here's my data.
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    2
I 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        110
In reality, the data is more complicated than this, but this represents what I need to do.

It takes too long to scan thru the Guest.dbf doing lookups for each Emp.
I'm able to do it for a given Guest.Date, but I really need to do it for multiple Guest.Date at once. It takes too long to do it for each Guest.Date and Union the results together.
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

TIA
Bill Morris
Next
Reply
Map
View

Click here to load this message in the networking platform