Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using recursion in SQL
Message
From
08/07/1999 08:04:16
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00238417
Message ID:
00238758
Views:
9
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
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform