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

Recursive Query - response (14) by dnoeth

$
0
0

Hi Sarah,
assuming your actual data is not based on increasing values you need to do a recursion starting with the LATEST_DND:

WITH RECURSIVE cte(DND_NO, REC1, LATEST_DND) AS
 (
   SELECT DND_NO, REC1, DND_NO AS LATEST_DND
   FROM tab
   WHERE REC1 = 0
   
   UNION ALL
   
   SELECT t2.DND_NO, t2.REC1, cte.LATEST_DND
   FROM cte JOIN tab AS t2
   ON t2.REC1 = cte.DND_NO 
 )
SELECT * FROM cte;

 
What are you trying to calculate here:

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

What's the datatype of A.ACT_DATE?


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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