Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using recursion in SQL
Message
From
08/07/1999 09:03:49
 
 
To
07/07/1999 14:04:11
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00238417
Message ID:
00238815
Views:
15
Try this, but be aware that you only can recurse to 25 (?) levels in VFP:
CREATE CURSOR ResultCur (IDISM I)
=RecurseFunc(4)

FUNCTION RecurseFunc
	LPARAMETERS tiKey
	LOCAL laTmp, liRows, i
	DIMENSION laTmp[1]
	SELECT * FROM TestCur WHERE IDCMP = tiKey INTO ARRAY laTmp
	liRows = _TALLY
	FOR i = 1 TO liRows
		IF !ISNULL(laTmp[i, 3])
			INSERT INTO ResultCur VALUES (laTmp[i, 3])
		ENDIF
		IF !ISNULL(laTmp[i, 2])
			=RecurseFunc(laTmp[i, 2])
		ENDIF
	ENDFOR
RETURN
Arne


>I have a table with the follow records:
>
>IDCMP CHILDIDCMP IDISM
>1 NULL 10507
>2 NULL 10485
>3 NULL 13259
>4 NULL 14987
>4 16 NULL
>10 1 NULL
>16 NULL 14000
>16 3 NULL
>16 10 NULL
>
>I need to retrive ALL values of IDISM included in a IDCMP. For example: the values from IDISM in IDCMP = 4 are 14987,14000,13259,10507. Is it possible to use a recursion SQL statement to do this?
>
>I would appreciate any help that could be given.
>
>Thanks in advance.
>Augusto.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform