--Ejecute este procedimiento contra la base de datos DBSAL
CREATE VIEW VAACL AS SELECT ANTCLIE.ANT_TIP AS TIP,ANTCLIE.ANT_NUM AS NUM, 
    ANTCLIE.ANT_CIA AS CIA, ANTCLIE.ANT_VAL AS VAL, 
    ISNULL(SUM(APLICAANT.APL_VAL), 0) AS SVAL
FROM ANTCLIE LEFT JOIN
    APLICAANT ON ANTCLIE.ANT_CIA = APLICAANT.APL_CDC AND 
    ANTCLIE.ANT_NUM = APLICAANT.APL_NUM AND 
    ANTCLIE.ANT_TIP = APLICAANT.APL_TIP
GROUP BY ANTCLIE.ANT_TIP, ANTCLIE.ANT_NUM, 
    ANTCLIE.ANT_CIA, ANTCLIE.ANT_VAL
GO
CREATE VIEW VAANT AS SELECT ANTICIPOS.ANT_TIP AS TIP, 
    ANTICIPOS.ANT_NUM AS NUM, ANTICIPOS.ANT_CIA AS CIA, 
    ANTICIPOS.ANT_VAL AS VAL, 
    ISNULL(SUM(APLANT.APL_VAL - APLANT.APL_DEV), 0) 
    AS SVAL
FROM ANTICIPOS LEFT JOIN
    APLANT ON ANTICIPOS.ANT_CIA = APLANT.APL_CAN AND 
    ANTICIPOS.ANT_NUM = APLANT.APL_ANT AND 
    ANTICIPOS.ANT_TIP = APLANT.APL_TAN
GROUP BY ANTICIPOS.ANT_TIP, ANTICIPOS.ANT_NUM, 
    ANTICIPOS.ANT_CIA, ANTICIPOS.ANT_VAL
GO
CREATE VIEW VACXC AS SELECT VENCIMIENTOS.VCE_TIP AS TIP, 
    VENCIMIENTOS.VCE_NUM AS NUM, 
    VENCIMIENTOS.VCE_CIA AS CIA, 
    VENCIMIENTOS.VCE_NV AS NV, 
    VENCIMIENTOS.VCE_VAL AS VAL, 
    ISNULL(SUM(APLICAVCE.APL_VAL - APLICAVCE.APL_DEV), 0) 
    AS SVAL
FROM VENCIMIENTOS LEFT JOIN
    APLICAVCE ON 
    VENCIMIENTOS.VCE_TIP = APLICAVCE.APL_TIP AND 
    VENCIMIENTOS.VCE_NUM = APLICAVCE.APL_NUM AND 
    VENCIMIENTOS.VCE_CIA = APLICAVCE.APL_CDC AND 
    VENCIMIENTOS.VCE_NV = APLICAVCE.APL_NV
GROUP BY VENCIMIENTOS.VCE_TIP, VENCIMIENTOS.VCE_NUM, 
    VENCIMIENTOS.VCE_CIA, VENCIMIENTOS.VCE_NV, 
    VENCIMIENTOS.VCE_VAL
GO
CREATE VIEW VACXP AS SELECT CUENTASPORPAGAR.VCE_TIP AS TIP, 
    CUENTASPORPAGAR.VCE_NUM AS NUM, 
    CUENTASPORPAGAR.VCE_CIA AS CIA, 
    CUENTASPORPAGAR.VCE_NV AS NV, 
    CUENTASPORPAGAR.VCE_NIT AS NIT, 
    CUENTASPORPAGAR.VCE_VAL AS VAL, 
    ISNULL(SUM(APLICACXP.APL_VAL - APLICACXP.APL_DEV), 0) 
    AS SVAL
FROM CUENTASPORPAGAR LEFT JOIN
    APLICACXP ON 
    CUENTASPORPAGAR.VCE_TIP = APLICACXP.APL_TIP AND 
    CUENTASPORPAGAR.VCE_NUM = APLICACXP.APL_NUM AND 
    CUENTASPORPAGAR.VCE_CIA = APLICACXP.APL_CDC AND 
    CUENTASPORPAGAR.VCE_NV = APLICACXP.APL_NV AND 
    CUENTASPORPAGAR.VCE_NIT = APLICACXP.APL_NIT
GROUP BY CUENTASPORPAGAR.VCE_TIP, 
    CUENTASPORPAGAR.VCE_NUM, 
    CUENTASPORPAGAR.VCE_CIA, CUENTASPORPAGAR.VCE_NV, 
    CUENTASPORPAGAR.VCE_NIT, CUENTASPORPAGAR.VCE_VAL
GO