Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using recursion in SQL
Message
 
 
À
07/07/1999 16:37:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00238417
Message ID:
00238758
Vues:
10
Hello Dore,

I need track all the elements (column IDISM) that beleongs hierarchy with any
composition (column IDCMP). In your code, the cursor "cur_4" retrives only the "top elements". I need to go deeper. The composition 4 (column IDCMP) relates with the element 14987 but with another composition, 16 (for wich relates with element 14000 and composition 3, and so on...).I tried this recursive function but it didn't worked:

FUNCTION PEGAINS
LPARAMETERS CODCOMP
SELE RECCMP
GO TOP
=SEEK(CODCOMP,'RECCMP','ind1')
DO WHILE CODCOMP = RECCMP.IDCMP AND !EOF()
IF !ISNULL(CHILDIDCMP)
=PEGAINS(CHILDIDCMP)
ELSE
? allt(str(IDCMP))+' - '+allt(str(IDISM))
ENDIF
SKIP
ENDDO


>The fact that you are asking about recursion suggests that you want to do it iterarively (for each value of IDCMP not merely IDCMP = 4 as in your example.
>Will this work for you?
>
>SELECT IDCMP FROM yourtable GROUP BY 1 INTO ARRAY a_idcmp
>FOR EACH idc IN a_idcmp
> cursorname = 'curs_' + alltrim(str(idc,5))
> SELECT IDISM DISTINCT FROM yourtable ;
> WHERE IDCMP = idc ;
> INTO CURSOR &cursorname
>ENDFOR
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform