Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Missing records and need to be inserted in tables
Message
De
23/06/2000 21:38:43
Cindy Winegarden
Duke University Medical Center
Durham, Caroline du Nord, États-Unis
 
 
À
23/06/2000 12:15:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00383837
Message ID:
00384162
Vues:
31
Paul,

Interesting project.

Be sure you test on a small set of data to get an idea how fast it will go. I wrote something quickly once and it was very slow, and I kept debating whether to kill it and re-write or just wait.

Here's some untested code. You will want to add an index on (EmpNo + DTOS(Date) + Code) and another on EmpNo in the Absence table. It may take awhile if the table is large.

Add STR() if the EmpNo is numeric.
*!* Make a table to hold the records we accumulate 
*!* Don't want to add to Absence table right away 
*!*     because that will give us more junk to sort through!
SELECT Absence
COPY STRUCTURE TO NewTable.dbf	&& Don't copy index

*!* Go through your list of employees one by one
SELECT Employee
SCAN
	cEmployeeTable = Employee.Empno
	IF FILE(Employee.Empno)
		USE (Employee.Empno) IN 0 ALIAS EmployeeTable

		MyEmpNo = Employee.Empno

		*!* Part 1 - Get records missing from Absence
                *!*     and put them in NewTable till we're done
		SELECT ;
                        MyEmpNo AS Empno, ;
                        EmployeeTable.DATE, ;
                        EmployeeTable.CODE ;
			FROM EmployeeTable ;
			WHERE ;
			(MyEmpNo + ;
                        DTOS(EmployeeTable.DATE) + ;
                        EmployeeTable.CODE) ;
			NOT IN ;
			(SELECT Absence.Empno + Absence.DATE + Absence.CODE ;
			FROM Absence) ;
			INTO CURSOR Temp1

		SELECT NewTable
		APPEND FROM DBF("Temp1")

		*!* Part 2 - Add missing records to individual employee tables
		SELECT Absence.DATE, Absence.CODE ;
			FROM Absence ;
			WHERE Absence.Empno = MyEmpNo ;
			AND (DTOS(Absence.DATE) + Absence.CODE) ;
			NOT IN ;
			(SELECT DTOS(EmployeeTable.DATE) + EmployeeTable.CODE ;
                        FROM Absence) ;
			INTO CURSOR Temp2

		SELECT EmployeeTable
		APPEND FROM DBF("Temp2")

	ELSE
		* Is lack of a table a problem?
	ENDIF

ENDSCAN

*!* Now put those records we've been holding 
*!*    into Absence where they belong.
SELECT Absence
APPEND FROM NewTable.dbf
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform