Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Do This With A JOIN?
Message
From
29/12/2005 13:21:00
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01081733
Message ID:
01081743
Views:
9
>I have a header table, LineTemp, with is related into Details.
>
>For each LineTemp record, I want to do the code inside the DO WHILE loop
>for all of the Detail records.
>
>I want to do all of this more efficiently. I'm guessing there's a way to do
>this with a JOIN, but I'm not sure of the syntax.
>
>
>
>SELECT LineTemp
>SET RELATION TO BoIdBase INTO Details
>		
>** Loop once for each line item record
>SCAN
>
> ** Clear the number cleared counter
>  m.NumCleared = 0
>
>  ** Loop once for each detail record belonging to the
>  ** current line item
>  SELECT Details
>  DO WHILE BoIdBase = LineTemp.BoIdBase
>
>    ** If the record is active, and has an air time and falls in the
>    ** date range, then count it
>    IF Details.RecType = "A" AND;
>       NOT EMPTY(AirTime) AND ;
>       BETWEEN(AirDate, dStartDate ,dEndDate)
>			
>         ** Increment the number cleared variable		
>         m.NumCleared = m.NumCleared + 1
>
>    ENDIF
>
>    IF EOF()
>      EXIT
>    ELSE
>     SKIP 1
>    ENDIF
>
>  ENDDO
>
>  SELECT LineTemp
>  GATHER MEMVAR
>
>ENDSCAN
>
VFP VERSION ??

with XBASE, TRY
SELECT LineTemp
SCAN
  SELECT Details
  SET KEY TO LineTemp.BoIdBase 
  COUNT FOR RecType == "A" AND NOT EMPTY(AirTime) AND BETWEEN(AirDate, m.dStartDate , m.dEndDate) TO NumCleared
  SELECT LineTemp
  REPLACE NumCleared WITH m.NumCleared
ENDSCAN
SET KEY TO IN Details
Previous
Reply
Map
View

Click here to load this message in the networking platform