CREATE MULTISET TABLE ...................................................HM_CIMA_RCC_CLASS AS (
SELECT A.PERIODO,
A.RUC,
M.CODSBS,
(SUBSTR(A.PERIODO,1,4)*12+SUBSTR(A.PERIODO,5,2))-((B.CODMES/100)*12+B.CODMES mod 100) AS DIF,
B.CTDENTIDADREPORTANTE,
B.PCTNORMAL,
B.PCTCPP,
B.PCTDEFICIENTE,
B.PCTDUDOSO,
B.PCTPERDIDA
FROM ..................................TABLA_BASE_DE_IBK_DATA A
LEFT JOIN ............V_RSK_FCT_MAEPERSONA_RCC M
ON A.RUC = (CASE WHEN M.NUMDOCTRIB IS NULL OR M.NUMDOCTRIB='.' OR M.NUMDOCTRIB LIKE '' THEN M.NUMDOCTRIB_TRDT ELSE M.NUMDOCTRIB END)
LEFT JOIN ................V_RSK_FCT_MAECLASIFRCC B ON M.CODSBS=B.CODSBS AND
(SUBSTR(A.PERIODO,1,4)*12+SUBSTR(A.PERIODO,5,2)) - ((B.CODMES/100)*12+B.CODMES mod 100)>=2 AND
(SUBSTR(A.PERIODO,1,4)*12+SUBSTR(A.PERIODO,5,2)) - ((B.CODMES/100)*12+B.CODMES mod 100)<=13
)
WITH DATA PRIMARY INDEX (PERIODO, RUC);
Add a code snippet to your website: www.paste.org