Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

recursive query numeric overflow issue - forum topic by Arun1377

$
0
0

Hi All,
I am using recursive query to fetch the top most hireracy of the relation. I have data as shown below:
 
Manager Reportee Department
1             2             ABC 
2             3             ABC 
3             4             ABC 
3             1             ABC 
4             5             ABC 
Here 4 is manager of 5, 3 is manager of 4, 2 is manager of 3, 1 is manager of 2. So the top most level manager is 1.
I am using recursive script to acheive this. But since i am having one more record saying 3 is manger of 1, it gets into infinite loop :(.
I need to stop the loop if the manager id comes again in the loop, in this sceanerio 3 comes twice in manager id. I need to have a check for re-occurance of the manager id in the loop and exit it out.
PFB the recursive query i have used:
with recursive recursive_T3(manager,reportee,loopno)
as
(
sel B.manager ,
B.reportee ,
0
from DB_TEST.T3 B
where B.B = 5
union all
sel B.manager ,
T2.reportee ,
T2.loopno+1
from DB_TEST.T3 B, recursive_T3 T2
where B.B = T2.manager
)
sel * from recursive_T3 where loopno = (sel max(loopno) from recursive_T3);
Kindly help to sort this out.
--Arun
 
 

 

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>