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

Recursive Query - response (11) by Sarah_07

$
0
0

I have tried this using many left outer joins. But the hierarchy level wouldn't change for some records. Dont know how to overcome that issue. Any help would be much appreciated.

SELECT  A.PRD_END_DT,A.DND_NO,
CASE WHEN A.ACT_DATE='2020-12-31'
THEN '0' ELSE A.REC1
END AS DRVD_REC1,
CASE WHEN (A.ACT_DATE='2020-12-31' OR 
(SUBSTR(A.ACT_DATE,4,2) < EXTRACT(DAY FROM A.PRD_END_DT)) OR
(SUBSTR(A.ACT_DATE,4,2) = EXTRACT(DAY FROM A.PRD_END_DT) AND SUBSTR(A.ACT_DATE,1,2) <= EXTRACT(MONTH FROM A.PRD_END_DT)))
THEN 'Y' ELSE 'N' END AS ACT_CURR_IND,
CASE WHEN ACT_CURR_IND ='N' THEN A.HOME_DND ELSE A.DND_NO END AS HME_DND,
CASE WHEN ACT_CURR_IND ='N'  THEN HME_DND ELSE  
CASE WHEN DRVD_REC1<>0 THEN DRVD_REC1 ELSE HME_DND END END AS LATEST_DND,
CASE WHEN (DRVD_REC1 IS NULL OR DRVD_REC1 = 0) THEN LATEST_DND ELSE DRVD_REC1 END AS LDND

FROM ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP A
LEFT OUTER JOIN ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP B
ON A.REC1=B.DND_NO
LEFT OUTER JOIN ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP C
ON B.REC1=C.DND_NO
LEFT OUTER JOIN ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP D
ON C.REC1=D.DND_NO
LEFT OUTER JOIN ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP E
ON D.REC1= E.DND_NO
ORDER BY A.DND_NO

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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