Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP and .NET Data Comparison
Message
De
28/12/2005 07:31:42
 
 
À
28/12/2005 05:45:31
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Divers
Thread ID:
01080965
Message ID:
01081205
Vues:
12
Consider an employee table. Every employee has a chief (Chief_fk), except the chairman (.NULL). Now given an employee, give me the entire path from that employee to the chairman. The record based solution is far simpler than the set oriented solution:


USE EMPLOYEE
GO RECCOUNT()*RAND() && Get a random record
? Firstname+" "+Lastname
DO WHILE SEEK(Chief_fk,"Employee","emp_pk")
?? "\"+Firstname+" "+Lastname
ENDDO


Walter,

FWIW, T-SQL in SQL Server 2005 allows developers to build recursive queries through common table expressions:
WITH ResultSet (FirstName, LastName, Parent_PK_Value)
   AS (SELECT FirstName, LastName, Chief_FK  
       FROM Employee
          WHERE Emp_PK = <somekey>                                          -- anchor query
       UNION ALL 
          SELECT Employee.FirstName, Employee.LastName, Chief_FK            -- recursive query  
             FROM Employee
               INNER JOIN ResultSet ON Parent_PK_Value = Employee.Emp_PK)

SELECT * FROM ResultSet
I've run this on a small table (few thousand rows), I'm curious to try it on something larger.

Kevin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform