Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

iteration criteria in a recursive SQL

$
0
0
Hallo everyone,

I have successfully run a recursive code with following recursion join criteria:

Code:

where
        and ...
        and ...   
        and a.iterationColumn = b.iterationColumn + 1
        and ...

I recognized, that in column b.iterationColumn on my base database not completely all numbers are adding 1:

ideal case:
1 2 3 4 5 6 ... 100
1 2 3 4 5 6 ... 117
1 2 3 4 5 6 ... 218

trouble case:
1 3 4 5 7 8 ... 109

As we can see, in the trouble case, the iteration criteria will not be able to iterate, since the join criteria ist
Code:

b.iterationColumn + 1
Thus, I would like to ask for ideas, how I can code the iteration criteria, so that all cases will be covered. Instead of taking the criteria + 1, I am thinking of taking an iteration criteria, which would say: TAKE THE NEXT BIGGER NUMBER (NOT RANDOMLY, BUT THE NEXT BIGGER SMALLEST NUMBER). For example from the above trouble case:
after 1, the recursive SQL should take 3 instead of randomly take 4 or 5.

Thank you for your ideas.

Regards,
Ratna

Viewing all articles
Browse latest Browse all 13329

Trending Articles