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

Recursive Query - response (4) by Sarah_07

$
0
0

Khurram,
Actually I have to modify my code using recursive query.
This is my actual query which is not working as expected. So my friend suggested me to use recursive query which is new to me. So asking out for help.

INSERT INTO TEMP_REC1
SELECT PRD_END_DT,RECORD_ID,
CASE WHEN ACT_DATE='2020-12-31'
THEN '0' ELSE REC1
END AS REC1,
CASE WHEN (ACT_DATE='2020-12-31' OR 
(SUBSTR(ACT_DATE,4,2) < EXTRACT(DAY FROM PRD_END_DT)) OR
(SUBSTR(ACT_DATE,4,2) = EXTRACT(DAY FROM PRD_END_DT) AND SUBSTR(ACT_DATE,1,2) <= EXTRACT(MONTH FROM PRD_END_DT)))
THEN 'Y' ELSE 'N' END AS ACT_CURR_IND
FROM ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP ;


SELECT
S.PRD_END_DT,
S.CC,
S.DND_NO,
S.LDND

FROM (
SELECT A.PRD_END_DT,A.CC,A.DND_NO,
CASE WHEN B.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 B.REC1 <> 0 THEN B.REC1
ELSE HME_DND END END AS LATST_DND,

CASE WHEN /*COALESCE(b.REC1,0) =0*/( B.REC1 IS NULL OR B.REC1 =0)
THEN LATST_DND
else B.REC1 END AS LDND

FROM ICDW_XLOB_PRSN_D9_W.DND_XREF_TEMP A
LEFT OUTER JOIN  ICDW_XLOB_PRSN_D9_W.TEMP_REC1 B
ON B.REC1=A.DND_NO
and a.DND_NO = HME_DND
AND A.DND_NO = LATST_DND
)S

 I have yet to start writing the code. Your help would be much appreciated.


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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