recursive way ¿?


recursive way ¿?


I have a table like this

COD      DESC            LEVEL

01         FATHER-1     01

01         SON-1          02

01         SON-2          02

01         FATHER-2     01

01         FATHER-3     01

01         SON-1          02

and I need to create a new table from it like this

01         FATHER-1    

01         FATHER-1    SON-1 

01         FATHER-1    SON-2 

01         FATHER-2

01         FATHER-3

01         FATHER-3    SON-1 

this is posible with terradata ¿? with a recursive query ¿?

thank you for your help.

Senior Supporter

Re: recursive way ¿?

Yes, recursive query should do. check the forum, there exists different examples.

But how do you link son-1 to father-1 and father-3 but not to father-2?

I think your base table is missing the father - son relation...


Re: recursive way ¿?

Well this is the problem.  The father of the son is the first father directly upper.

If I could read ir secuencialy , with a simple script It should work. But with teradata I'm not sure that this is posible.

I would do something like ; 

while end of file do

   if LEVEL = '01'  then


             print DESC


          print $var

          print DESC

Senior Supporter

Re: recursive way ¿?

But in an relational DB you do not have an order within the table.