Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using recursion in SQL
Message
From
09/07/1999 00:31:13
 
 
To
08/07/1999 07:37:54
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00238417
Message ID:
00239263
Views:
12
I guess you can do something like (I wrote the code here on UT, so, it's not tested):
select IDCMP from Source into cursor IDCMPs where IDCMP = InitialIDCMP
lbContinue = .t.
do while lbContinue
   lnPreviousRecCount = _tally
   select distinct IDCMP from IDCMPs into cursor IDCMPsTemp;
   union select distinct CHILDIDCMP as IDCMP from Source, IDCMPs;
           where IDCMPs.IDCMP = Source.CHILDIDCMP
   if _tally = lnPreviousRecCount
       *-- No new records.
       lbContinue = .f.
   endif
   use in IDCMPs
   use IDCMPsTemp again alias IDCMPs in 0
   use in IDCMPsTemp
enddo

*-- Now, the final result
select distinct IDISM from Source, IDCMPs where Source.IDCMP = IDCMPs.IDCMP
Vlad

>>>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.
>>
>>I don't understand what you mean by "included" here. Can you explain it?
>>
>>Vlad
>
>Hi Vlad,
>
> Sorry for my english. I will try to explain my problem.
> I have a table with a autorelation (column IDCMP relates with CHILDIDCMP). The column IDCMP would be the identification from a composition of elements (column IDISM). One composition can refer to one or more composition and elements. For example: composition 4 refers to composition 16 (that by your time refers to composition 3 e 10, and so on...) and element 14987. I need to track all the elements that are parts of a composition AND in all "subcompositions" related with it (I need to expand an encoded hierarchy).
>
>Thanks.
>Augusto.
Previous
Reply
Map
View

Click here to load this message in the networking platform