Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as SQL by registered user vvillacorta ( 3 years ago )
CREATE MULTISET TABLE .......................................................HM_CIMA_RCC_2 AS (
SELECT PERIODO, RUC, DIF2,
/*SALDOS*/
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0002' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDADIRECTA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0003' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINDIRECTA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd in ('0002','0003') THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDATOTAL,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAPRODPERSONA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Producto_RCC_cd='0025' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAPREPERSONAL,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Producto_RCC_cd='0029' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDATC,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Producto_RCC_cd='0007' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDACREDCONVENIO,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Producto_RCC_cd='0006' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDACREDHIPOTECARIO,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Producto_RCC_cd='0008' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDACREDVEHICULAR,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0005' THEN Saldo_Amt ELSE NULL END),0) AS MTOFAE,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0007' THEN Saldo_Amt ELSE NULL END),0) AS MTOGARANTIAFAE,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0008' THEN Saldo_Amt ELSE NULL END),0) AS MTOGARANTIAREACTIVA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0006' THEN Saldo_Amt ELSE NULL END),0) AS MTOGARANTIAS,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0009' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINMOBILIARIA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0011' THEN Saldo_Amt ELSE NULL END),0) AS MTOREACTIVA,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0012' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAREPROGRAMADOS,
COALESCE(SUM(CASE WHEN Situacion_RCC_cd='0001' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDACASTIGADA,
COALESCE(SUM(CASE WHEN Situacion_RCC_cd='0002' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAJUDICIAL,
COALESCE(SUM(CASE WHEN Situacion_RCC_cd='0003' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAREESTRUCTURADO,
COALESCE(SUM(CASE WHEN Situacion_RCC_cd='0004' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAREFINANCIADO,
COALESCE(SUM(CASE WHEN Situacion_RCC_cd='0007' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAVENCIDO,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Situacion_RCC_cd='0007' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDABCAPERSONAVCD,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Situacion_RCC_cd='0004' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDABCAPERSONAREF,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0001' AND Situacion_RCC_cd='0002' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDABCAPERSONAJUD,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0009' AND Situacion_RCC_cd='0007' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINMOBILIARIAVCD,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0009' AND Situacion_RCC_cd='0004' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINMOBILIARIAREF,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0009' AND Situacion_RCC_cd='0002' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINMOBILIARIAJUD,
COALESCE(SUM(CASE WHEN Tipo_Producto_RCC_cd='0009' AND Situacion_RCC_cd='0003' THEN Saldo_Amt ELSE NULL END),0) AS MTODEUDAINMOBILIARIAREES
FROM (
SELECT A.*,
(CASE WHEN A.DIF IS NULL THEN 2 ELSE A.DIF END ) AS DIF2
FROM .......................................................HM_CIMA_RCC_1 A
) RCC
WHERE flg_lin_mercado='S'
GROUP BY PERIODO, RUC, DIF2
)
WITH DATA PRIMARY INDEX (PERIODO, RUC, DIF2);
Revise this Paste