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

Get previous column vale till it reaches another not null value - forum topic by bikky6

$
0
0

CT LKP(EMPNO INTEGER,TYPE_CD VARCHAR(10),EFF_DT DATE);
INS INTO LKP VALUES(1,'A','2013-01-01');
INS INTO LKP VALUES(1,'B','2014-01-01');
CT MAIN(EMPNO INTEGER,EFF_DT DATE);
INS INTO MAIN VALUES(1,'2012-01-01');
INS INTO MAIN VALUES(1,'2013-01-01');
INS INTO MAIN VALUES(1,'2013-03-01');
INS INTO MAIN VALUES(1,'2013-05-01');
INS INTO MAIN VALUES(1,'2013-07-01');
INS INTO MAIN VALUES(1,'2013-09-01');
INS INTO MAIN VALUES(1,'2014-01-01');
INS INTO MAIN VALUES(1,'2014-02-01');
INS INTO MAIN VALUES(1,'2014-03-01');

SEL
M.EMPNO AS MAIN_EMP,
M.EFF_DT AS MAIN_DT,
L.TYPE_CD
FROM MAIN M LEFT JOIN LKP L ON M.EMPNO=L.EMPNO AND M.EFF_DT=L.EFF_DT
Expected O/P
 MAIN_EMP MAIN_DT TYPE_CD
1 1 2012-01-01 NULL
2 1 2013-01-01 A
3 1 2013-03-01 A
4 1 2013-05-01 A
5 1 2013-07-01 A
6 1 2013-09-01 A
7 1 2014-01-01 B
8 1 2014-02-01 B
9 1 2014-03-01 B
 
 
 

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>