INSERT INTO CN_SALDO
                    SELECT *
                    FROM
                    (
                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_sig.ID_CIA, sal_old.ID_CIA) AS ID_CIA,
                     NVL(sal_sig.ID_CEN_OP, sal_old.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     1 AS ID_PERIODO_CONTABLE,
                     NVL(sal_sig.ID_CLASE_CUENTA, sal_old.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_sig.ID_GRUPO_CUENTA, sal_old.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_sig.ID_CUENTA_MAYOR, sal_old.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_sig.ID_CATALOGO, sal_old.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_sig.ID_MAE_TER, sal_old.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_sig.ID_AUXILIAR, sal_old.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_sig.ID_SUB_AUX, sal_old.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_sig.ID_CENTRO_COSTO, sal_old.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO, sal_old.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_sig.SUBCUENTA, sal_old.SUBCUENTA) AS SUBCUENTA,
                     sal_old.SALDO_ACTUAL AS SALDO_ANTERIOR,
                     NVL(sal_sig.DEBITO,0) AS DEBITO,
                     NVL(sal_sig.CREDITO,0) AS CREDITO,
                     sal_old.SALDO_ACTUAL + NVL(sal_sig.SALDO_PERIODO, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 1

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =1
                    ) sal_sig
                    RIGHT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2010 AND ID_PERIODO_CONTABLE =13
                    ) sal_old ON
                     sal_sig.ID_CIA = sal_old.ID_CIA AND
                     sal_sig.ID_CEN_OP = sal_old.ID_CEN_OP AND
                     sal_sig.SUBCUENTA = sal_old.SUBCUENTA AND
                     NVL(sal_sig.ID_MAE_TER,0) = NVL(sal_old.ID_MAE_TER,0) AND
                     NVL(sal_sig.ID_AUXILIAR,0) = NVL(sal_old.ID_AUXILIAR,0) AND
                     NVL(sal_sig.ID_SUB_AUX,0) = NVL(sal_old.ID_SUB_AUX,0) AND
                     NVL(sal_sig.ID_CENTRO_COSTO,0) = NVL(sal_old.ID_CENTRO_COSTO,0) AND
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO,0) = NVL(sal_old.ID_SUB_CENTRO_COSTO,0)
                    )

                    UNION

                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_old.ID_CIA, sal_sig.ID_CIA) AS ID_CIA,
                     NVL(sal_old.ID_CEN_OP, sal_sig.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     1 AS ID_PERIODO_CONTABLE,
                     NVL(sal_old.ID_CLASE_CUENTA, sal_sig.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_old.ID_GRUPO_CUENTA, sal_sig.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_old.ID_CUENTA_MAYOR, sal_sig.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_old.ID_CATALOGO, sal_sig.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_old.ID_MAE_TER, sal_sig.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_old.ID_AUXILIAR, sal_sig.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_old.ID_SUB_AUX, sal_sig.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_old.ID_CENTRO_COSTO, sal_sig.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_old.ID_SUB_CENTRO_COSTO, sal_sig.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_old.SUBCUENTA, sal_sig.SUBCUENTA) AS SUBCUENTA,
                     NVL(sal_old.SALDO_ACTUAL,0) AS SALDO_ANTERIOR,
                     sal_sig.DEBITO AS DEBITO,
                     sal_sig.CREDITO AS CREDITO,
                     sal_sig.SALDO_PERIODO + NVL(sal_old.SALDO_ACTUAL, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 1

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =1
                    ) sal_sig
                    LEFT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2010 AND ID_PERIODO_CONTABLE =13
                    ) sal_old ON
                     sal_old.ID_CIA = sal_sig.ID_CIA AND
                     sal_old.ID_CEN_OP = sal_sig.ID_CEN_OP AND
                     sal_old.SUBCUENTA = sal_sig.SUBCUENTA AND
                     NVL(sal_old.ID_MAE_TER,0) = NVL(sal_sig.ID_MAE_TER,0) AND
                     NVL(sal_old.ID_AUXILIAR,0) = NVL(sal_sig.ID_AUXILIAR,0) AND
                     NVL(sal_old.ID_SUB_AUX,0) = NVL(sal_sig.ID_SUB_AUX,0) AND
                     NVL(sal_old.ID_CENTRO_COSTO,0) = NVL(sal_sig.ID_CENTRO_COSTO,0) AND
                     NVL(sal_old.ID_SUB_CENTRO_COSTO,0) = NVL(sal_sig.ID_SUB_CENTRO_COSTO,0)
                    )
                    )


****

INSERT INTO CN_SALDO
                    SELECT *
                    FROM
                    (
                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_sig.ID_CIA, sal_old.ID_CIA) AS ID_CIA,
                     NVL(sal_sig.ID_CEN_OP, sal_old.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     2 AS ID_PERIODO_CONTABLE,
                     NVL(sal_sig.ID_CLASE_CUENTA, sal_old.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_sig.ID_GRUPO_CUENTA, sal_old.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_sig.ID_CUENTA_MAYOR, sal_old.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_sig.ID_CATALOGO, sal_old.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_sig.ID_MAE_TER, sal_old.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_sig.ID_AUXILIAR, sal_old.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_sig.ID_SUB_AUX, sal_old.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_sig.ID_CENTRO_COSTO, sal_old.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO, sal_old.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_sig.SUBCUENTA, sal_old.SUBCUENTA) AS SUBCUENTA,
                     sal_old.SALDO_ACTUAL AS SALDO_ANTERIOR,
                     NVL(sal_sig.DEBITO,0) AS DEBITO,
                     NVL(sal_sig.CREDITO,0) AS CREDITO,
                     sal_old.SALDO_ACTUAL + NVL(sal_sig.SALDO_PERIODO, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 2

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =2
                    ) sal_sig
                    RIGHT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =1
                    ) sal_old ON
                     sal_sig.ID_CIA = sal_old.ID_CIA AND
                     sal_sig.ID_CEN_OP = sal_old.ID_CEN_OP AND
                     sal_sig.SUBCUENTA = sal_old.SUBCUENTA AND
                     NVL(sal_sig.ID_MAE_TER,0) = NVL(sal_old.ID_MAE_TER,0) AND
                     NVL(sal_sig.ID_AUXILIAR,0) = NVL(sal_old.ID_AUXILIAR,0) AND
                     NVL(sal_sig.ID_SUB_AUX,0) = NVL(sal_old.ID_SUB_AUX,0) AND
                     NVL(sal_sig.ID_CENTRO_COSTO,0) = NVL(sal_old.ID_CENTRO_COSTO,0) AND
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO,0) = NVL(sal_old.ID_SUB_CENTRO_COSTO,0)
                    )

                    UNION

                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_old.ID_CIA, sal_sig.ID_CIA) AS ID_CIA,
                     NVL(sal_old.ID_CEN_OP, sal_sig.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     1 AS ID_PERIODO_CONTABLE,
                     NVL(sal_old.ID_CLASE_CUENTA, sal_sig.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_old.ID_GRUPO_CUENTA, sal_sig.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_old.ID_CUENTA_MAYOR, sal_sig.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_old.ID_CATALOGO, sal_sig.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_old.ID_MAE_TER, sal_sig.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_old.ID_AUXILIAR, sal_sig.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_old.ID_SUB_AUX, sal_sig.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_old.ID_CENTRO_COSTO, sal_sig.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_old.ID_SUB_CENTRO_COSTO, sal_sig.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_old.SUBCUENTA, sal_sig.SUBCUENTA) AS SUBCUENTA,
                     NVL(sal_old.SALDO_ACTUAL,0) AS SALDO_ANTERIOR,
                     sal_sig.DEBITO AS DEBITO,
                     sal_sig.CREDITO AS CREDITO,
                     sal_sig.SALDO_PERIODO + NVL(sal_old.SALDO_ACTUAL, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 2

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =2
                    ) sal_sig
                    LEFT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =1
                    ) sal_old ON
                     sal_old.ID_CIA = sal_sig.ID_CIA AND
                     sal_old.ID_CEN_OP = sal_sig.ID_CEN_OP AND
                     sal_old.SUBCUENTA = sal_sig.SUBCUENTA AND
                     NVL(sal_old.ID_MAE_TER,0) = NVL(sal_sig.ID_MAE_TER,0) AND
                     NVL(sal_old.ID_AUXILIAR,0) = NVL(sal_sig.ID_AUXILIAR,0) AND
                     NVL(sal_old.ID_SUB_AUX,0) = NVL(sal_sig.ID_SUB_AUX,0) AND
                     NVL(sal_old.ID_CENTRO_COSTO,0) = NVL(sal_sig.ID_CENTRO_COSTO,0) AND
                     NVL(sal_old.ID_SUB_CENTRO_COSTO,0) = NVL(sal_sig.ID_SUB_CENTRO_COSTO,0)
                    )
                    )


****

INSERT INTO CN_SALDO
                    SELECT *
                    FROM
                    (
                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_sig.ID_CIA, sal_old.ID_CIA) AS ID_CIA,
                     NVL(sal_sig.ID_CEN_OP, sal_old.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     3 AS ID_PERIODO_CONTABLE,
                     NVL(sal_sig.ID_CLASE_CUENTA, sal_old.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_sig.ID_GRUPO_CUENTA, sal_old.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_sig.ID_CUENTA_MAYOR, sal_old.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_sig.ID_CATALOGO, sal_old.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_sig.ID_MAE_TER, sal_old.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_sig.ID_AUXILIAR, sal_old.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_sig.ID_SUB_AUX, sal_old.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_sig.ID_CENTRO_COSTO, sal_old.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO, sal_old.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_sig.SUBCUENTA, sal_old.SUBCUENTA) AS SUBCUENTA,
                     sal_old.SALDO_ACTUAL AS SALDO_ANTERIOR,
                     NVL(sal_sig.DEBITO,0) AS DEBITO,
                     NVL(sal_sig.CREDITO,0) AS CREDITO,
                     sal_old.SALDO_ACTUAL + NVL(sal_sig.SALDO_PERIODO, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 3

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =3
                    ) sal_sig
                    RIGHT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =2
                    ) sal_old ON
                     sal_sig.ID_CIA = sal_old.ID_CIA AND
                     sal_sig.ID_CEN_OP = sal_old.ID_CEN_OP AND
                     sal_sig.SUBCUENTA = sal_old.SUBCUENTA AND
                     NVL(sal_sig.ID_MAE_TER,0) = NVL(sal_old.ID_MAE_TER,0) AND
                     NVL(sal_sig.ID_AUXILIAR,0) = NVL(sal_old.ID_AUXILIAR,0) AND
                     NVL(sal_sig.ID_SUB_AUX,0) = NVL(sal_old.ID_SUB_AUX,0) AND
                     NVL(sal_sig.ID_CENTRO_COSTO,0) = NVL(sal_old.ID_CENTRO_COSTO,0) AND
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO,0) = NVL(sal_old.ID_SUB_CENTRO_COSTO,0)
                    )

                    UNION

                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_old.ID_CIA, sal_sig.ID_CIA) AS ID_CIA,
                     NVL(sal_old.ID_CEN_OP, sal_sig.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     3 AS ID_PERIODO_CONTABLE,
                     NVL(sal_old.ID_CLASE_CUENTA, sal_sig.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_old.ID_GRUPO_CUENTA, sal_sig.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_old.ID_CUENTA_MAYOR, sal_sig.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_old.ID_CATALOGO, sal_sig.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_old.ID_MAE_TER, sal_sig.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_old.ID_AUXILIAR, sal_sig.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_old.ID_SUB_AUX, sal_sig.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_old.ID_CENTRO_COSTO, sal_sig.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_old.ID_SUB_CENTRO_COSTO, sal_sig.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_old.SUBCUENTA, sal_sig.SUBCUENTA) AS SUBCUENTA,
                     NVL(sal_old.SALDO_ACTUAL,0) AS SALDO_ANTERIOR,
                     sal_sig.DEBITO AS DEBITO,
                     sal_sig.CREDITO AS CREDITO,
                     sal_sig.SALDO_PERIODO + NVL(sal_old.SALDO_ACTUAL, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 3

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =3
                    ) sal_sig
                    LEFT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =2
                    ) sal_old ON
                     sal_old.ID_CIA = sal_sig.ID_CIA AND
                     sal_old.ID_CEN_OP = sal_sig.ID_CEN_OP AND
                     sal_old.SUBCUENTA = sal_sig.SUBCUENTA AND
                     NVL(sal_old.ID_MAE_TER,0) = NVL(sal_sig.ID_MAE_TER,0) AND
                     NVL(sal_old.ID_AUXILIAR,0) = NVL(sal_sig.ID_AUXILIAR,0) AND
                     NVL(sal_old.ID_SUB_AUX,0) = NVL(sal_sig.ID_SUB_AUX,0) AND
                     NVL(sal_old.ID_CENTRO_COSTO,0) = NVL(sal_sig.ID_CENTRO_COSTO,0) AND
                     NVL(sal_old.ID_SUB_CENTRO_COSTO,0) = NVL(sal_sig.ID_SUB_CENTRO_COSTO,0)
                    )
                    )



*****
INSERT INTO CN_SALDO
                    SELECT *
                    FROM
                    (
                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_sig.ID_CIA, sal_old.ID_CIA) AS ID_CIA,
                     NVL(sal_sig.ID_CEN_OP, sal_old.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     4 AS ID_PERIODO_CONTABLE,
                     NVL(sal_sig.ID_CLASE_CUENTA, sal_old.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_sig.ID_GRUPO_CUENTA, sal_old.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_sig.ID_CUENTA_MAYOR, sal_old.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_sig.ID_CATALOGO, sal_old.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_sig.ID_MAE_TER, sal_old.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_sig.ID_AUXILIAR, sal_old.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_sig.ID_SUB_AUX, sal_old.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_sig.ID_CENTRO_COSTO, sal_old.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO, sal_old.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_sig.SUBCUENTA, sal_old.SUBCUENTA) AS SUBCUENTA,
                     sal_old.SALDO_ACTUAL AS SALDO_ANTERIOR,
                     NVL(sal_sig.DEBITO,0) AS DEBITO,
                     NVL(sal_sig.CREDITO,0) AS CREDITO,
                     sal_old.SALDO_ACTUAL + NVL(sal_sig.SALDO_PERIODO, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 4

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =4
                    ) sal_sig
                    RIGHT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =3
                    ) sal_old ON
                     sal_sig.ID_CIA = sal_old.ID_CIA AND
                     sal_sig.ID_CEN_OP = sal_old.ID_CEN_OP AND
                     sal_sig.SUBCUENTA = sal_old.SUBCUENTA AND
                     NVL(sal_sig.ID_MAE_TER,0) = NVL(sal_old.ID_MAE_TER,0) AND
                     NVL(sal_sig.ID_AUXILIAR,0) = NVL(sal_old.ID_AUXILIAR,0) AND
                     NVL(sal_sig.ID_SUB_AUX,0) = NVL(sal_old.ID_SUB_AUX,0) AND
                     NVL(sal_sig.ID_CENTRO_COSTO,0) = NVL(sal_old.ID_CENTRO_COSTO,0) AND
                     NVL(sal_sig.ID_SUB_CENTRO_COSTO,0) = NVL(sal_old.ID_SUB_CENTRO_COSTO,0)
                    )

                    UNION

                    SELECT *
                    FROM
                    (
                    SELECT
                     NVL(sal_old.ID_CIA, sal_sig.ID_CIA) AS ID_CIA,
                     NVL(sal_old.ID_CEN_OP, sal_sig.ID_CEN_OP) AS ID_CEN_OP,
                     2011 AS ID_VIGENCIA,
                     4 AS ID_PERIODO_CONTABLE,
                     NVL(sal_old.ID_CLASE_CUENTA, sal_sig.ID_CLASE_CUENTA) AS ID_CLASE_CUENTA,
                     NVL(sal_old.ID_GRUPO_CUENTA, sal_sig.ID_GRUPO_CUENTA) AS ID_GRUPO_CUENTA,
                     NVL(sal_old.ID_CUENTA_MAYOR, sal_sig.ID_CUENTA_MAYOR) AS ID_CUENTA_MAYOR,
                     NVL(sal_old.ID_CATALOGO, sal_sig.ID_CATALOGO) AS ID_CATALOGO,
                     NVL(sal_old.ID_MAE_TER, sal_sig.ID_MAE_TER) AS ID_MAE_TER,
                     NVL(sal_old.ID_AUXILIAR, sal_sig.ID_AUXILIAR) AS ID_AUXILIAR,
                     NVL(sal_old.ID_SUB_AUX, sal_sig.ID_SUB_AUX) AS ID_SUB_AUX,
                     NVL(sal_old.ID_CENTRO_COSTO, sal_sig.ID_CENTRO_COSTO) AS ID_CENTRO_COSTO,
                     NVL(sal_old.ID_SUB_CENTRO_COSTO, sal_sig.ID_SUB_CENTRO_COSTO) AS ID_SUB_CENTRO_COSTO,
                     NVL(sal_old.SUBCUENTA, sal_sig.SUBCUENTA) AS SUBCUENTA,
                     NVL(sal_old.SALDO_ACTUAL,0) AS SALDO_ANTERIOR,
                     sal_sig.DEBITO AS DEBITO,
                     sal_sig.CREDITO AS CREDITO,
                     sal_sig.SALDO_PERIODO + NVL(sal_old.SALDO_ACTUAL, 0) AS SALDO_ACTUAL
                    FROM
                    (
                    SELECT *
                    FROM CN_SALDO_DEB_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE = 4

                    UNION

                    SELECT *
                    FROM CN_SALDO_CRE_SIN_ANT
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =4
                    ) sal_sig
                    LEFT JOIN
                    (
                    SELECT *
                    FROM CN_SALDO
                    WHERE ID_VIGENCIA =2011 AND ID_PERIODO_CONTABLE =3
                    ) sal_old ON
                     sal_old.ID_CIA = sal_sig.ID_CIA AND
                     sal_old.ID_CEN_OP = sal_sig.ID_CEN_OP AND
                     sal_old.SUBCUENTA = sal_sig.SUBCUENTA AND
                     NVL(sal_old.ID_MAE_TER,0) = NVL(sal_sig.ID_MAE_TER,0) AND
                     NVL(sal_old.ID_AUXILIAR,0) = NVL(sal_sig.ID_AUXILIAR,0) AND
                     NVL(sal_old.ID_SUB_AUX,0) = NVL(sal_sig.ID_SUB_AUX,0) AND
                     NVL(sal_old.ID_CENTRO_COSTO,0) = NVL(sal_sig.ID_CENTRO_COSTO,0) AND
                     NVL(sal_old.ID_SUB_CENTRO_COSTO,0) = NVL(sal_sig.ID_SUB_CENTRO_COSTO,0)
                    )
                    )

