Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Two table in one
Message
De
22/04/2007 01:17:04
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01218574
Message ID:
01218655
Vues:
15
Thanks a lot, I'll look through it.

>>>>Yes, sometimes 30.
>>>>>
>>>>>Can you have more then TWO records in Child table for a parent Id?
>>>>>
>>>>>BTW there is no need to post the question twice. If you didn't have any answer to your question you could click on your post and UPDATE it.
>>>
>>>Then what you want this table to looks like?
>>
>>Like written in the "MessageID:1218575", below "The result".
>>(Each child records should be in parent table in a separate field.)
>
>
>
>*** Just to define how many distinct names we have in child table
>SELECT MAX(Cnt) AS Cnt;
>       FROM (SELECT Id, COUNT(DISTINCT cField1) AS Cnt;
>                    FROM ChildTable;
>                    GROUP BY  Id) Tbl1;
>INTO CURSOR crsTest
>IF crsTest.Cnt = 0
>   MESSAGEBOX([What we must do now?])
>   RETURN
>ENDIF
>
>*** Creates a cursor where we will try to flat the Child table
>lcCreate = [CREATE CURSOR crsChid (Id int]
>FOR lnFor = 1 TO crsTest.Cnt
>    lcCreate = lcCreate + [, pcField] +TRANSFORM(lnFor)+[ C(3)]
>NEXT
>lcCreate = lcCreate + [)]
>&lcCreate
>
>
>*** Get ALL distinct names from Child table
>SELECT DISTINCT Id, cField1;
>       FROM ChildTable;
>       ORDER BY Id;
>INTO CURSOR crsTest && crsTest is not needed anymore
>
>lnId = 0
>lnNextField = 1
>SCAN
>   IF Id # m.lnId
>      lnNextField = 1
>      lnId        = crsTest.Id
>      APPEND BLANK IN crsChid
>   ENDIF
>   lcFldName = [pcField]+TRANSFORM(lnNextField)
>   REPLACE &lcFldName WITH crsTest.cField1 IN crsChid
>   lnNextField = lnNextField + 1
>ENDSCAN
>
>*** OK We Flated the cursor so the final result:
>
>SELECT *;
>       FROM ParentTable;
>       LEFT JOIN crsChild ON ParentTable.Id = crsChild.Id;
>INTO CURSOR crsFinal
>
>Not tested but you got the idea.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform