cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HANA SQL - Loop over table A and append rows to table B

martin_chambers
Participant
0 Likes
687

I would like to loop over a table with 3 fields and use the value in column LOOKUP_1 in each row to create a hierarchy. The hierarchy consists of several rows. I want to append these rows to a 2nd table. Thus, if my 1st table has 30 rows, I want my 2nd table to contain 30 * "several" rows.

So the steps are as follow

Create hierarchy for 1st row in 1st table where LOOKUP_1 = A.
The code below will create several rows for 1 hierarchy with the top node = A.
Append these rows to 2nd table.

Repeat for 2nd row in until last row in 1st table.

I'm not sure how to append within a loop.
Any help would be appreciated.

select node_id, parent_id from hierarchy ( source ( select SRC as node_id
                                        , TGT as parent_id
                                     from RSBKDTP
                                  )
                              start where TGT = A
                         )
;

<br>

Accepted Solutions (0)

Answers (0)