Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Migration

Status
Not open for further replies.

edjiga

Programmer
Jul 22, 2003
1
MX
Hi, I need help to migrate this SQL Informix to SQL Oracle.

Can someone help me please?

create view vreportefin (empresa,reporte,descreporte,grupo,nomgrupo,cuenta,descgrupo, cveperiodo,saldo,saldoant)
AS

SELECT
ct_mayor_general.numempresa,
ct_reporte.nombre_reporte,
ct_reporte.descripcion,
ct_reporte_grupos.grupo_reporte,
ct_reporte_grupos.nombre_grupo,
ct_reporte_cuenta.renglon_cuenta,
ct_reporte_cuenta.descripcion_grupo,
ct_mayor_general.cve_periodo,
sum((case when ct_reporte_cuenta.nat_cuenta = 'D' then (ct_mayor_general.saldo_inicial+ct_mayor_general.saldo_debito-
ct_mayor_general.saldo_credito)*ct_reporte_cuenta.operacion else (ct_mayor_general.saldo_inicial-ct_mayor_general.saldo_debito+
ct_mayor_general.saldo_credito)*ct_reporte_cuenta.operacion end)) saldo,
(SELECT
nvl(sum((case when rc2.nat_cuenta = 'D' then (mg2.saldo_inicial+mg2.saldo_debito-
mg2.saldo_credito)*rc2.operacion else (mg2.saldo_inicial-mg2.saldo_debito+
mg2.saldo_credito)*rc2.operacion end)), 0)
FROM
ct_reporte r2,ct_reporte_grupos rg2, ct_reporte_cuenta rc2, ct_mayor_general mg2, ct_cuenta_contable cc2
WHERE
r2.nombre_reporte=rg2.reporte and
mg2.cve_periodo = ct_mayor_general.cve_periodo-100
and mg2.numempresa = ct_mayor_general.numempresa
and mg2.numproy=ct_mayor_general.numproy
and mg2.numempresa=rc2.numempresa
and mg2.num_cuenta=rc2.num_cuenta
and mg2.sub_cuenta=rc2.sub_cuenta
and mg2.sub_subcuenta=rc2.sub_subcuenta
and rc2.reporte = ct_reporte_cuenta.reporte
and rc2.reporte=rg2.reporte
and rc2.grupo_reporte=rg2.grupo_reporte
and cc2.numempresa=mg2.numempresa
and cc2.num_cuenta=mg2.num_cuenta
and cc2.sub_cuenta=mg2.sub_cuenta
and cc2.sub_subcuenta=mg2.sub_subcuenta
and r2.nombre_reporte=ct_reporte. nombre_reporte
and rg2.grupo_reporte=ct_reporte_grupos.grupo_reporte
and rc2.renglon_cuenta=ct_reporte_cuenta.renglon_cuenta
and cc2.num_cuenta=ct_cuenta_contable.num_cuenta
and cc2.sub_cuenta=ct_cuenta_contable.sub_cuenta
and cc2.sub_subcuenta=ct_cuenta_contable.sub_subcuenta
) as saldo_ant
FROM
ct_reporte_grupos, ct_reporte_cuenta, ct_mayor_general, ct_cuenta_contable, ct_reporte
WHERE
ct_reporte.nombre_reporte=ct_reporte_grupos.reporte
AND ct_mayor_general.numempresa = 1
and ct_mayor_general.numempresa=ct_reporte_cuenta.numempresa
and ct_mayor_general.num_cuenta=ct_reporte_cuenta.num_cuenta
and ct_mayor_general.sub_cuenta=ct_reporte_cuenta.sub_cuenta
and ct_mayor_general.sub_subcuenta=ct_reporte_cuenta.sub_subcuenta
and ct_reporte_cuenta.reporte=ct_reporte_grupos.reporte
and ct_reporte_cuenta.grupo_reporte=ct_reporte_grupos.grupo_reporte
and ct_cuenta_contable.numempresa=ct_mayor_general.numempresa
and ct_cuenta_contable.num_cuenta=ct_mayor_general.num_cuenta
and ct_cuenta_contable.sub_cuenta=ct_mayor_general.sub_cuenta
and ct_cuenta_contable.sub_subcuenta=ct_mayor_general.sub_subcuenta
group by 1,2,3,4,5,6,7,8,10;



 
Edjiga,

Try the rewrite below.
The CASE becomes Oracle DECODE.
The "sub-query" for saldo_ant needs to be moved to the
FROM clause.
Obviously I cannot test the solution without your schema.

******

create view vreportefin (empresa,reporte,descreporte,grupo,nomgrupo,cuenta,descgrupo, cveperiodo,saldo,saldoant)
AS
SELECT
ct_mayor_general.numempresa,
ct_reporte.nombre_reporte,
ct_reporte.descripcion,
ct_reporte_grupos.grupo_reporte,
ct_reporte_grupos.nombre_grupo,
ct_reporte_cuenta.renglon_cuenta,
ct_reporte_cuenta.descripcion_grupo,
ct_mayor_general.cve_periodo,
/*
Oracle DECODE
*/
sum(DECODE(ct_reporte_cuenta.nat_cuenta, 'D',
(ct_mayor_general.saldo_inicial+ct_mayor_general.saldo_debito-ct_mayor_general.saldo_credito)*ct_reporte_cuenta.operacion,
(ct_mayor_general.saldo_inicial-ct_mayor_general.saldo_debito+ct_mayor_general.saldo_credito)*ct_reporte_cuenta.operacion)) as saldo,
slda.saldo_ant
FROM
ct_reporte_grupos, ct_reporte_cuenta, ct_mayor_general, ct_cuenta_contable, ct_reporte,
(SELECT
nvl(sum((DECODE(rc2.nat_cuenta, 'D', (mg2.saldo_inicial+mg2.saldo_debito-mg2.saldo_credito)*rc2.operacion,
(mg2.saldo_inicial-mg2.saldo_debito+mg2.saldo_credito)*rc2.operacion)), 0)
FROM
ct_reporte r2,ct_reporte_grupos rg2, ct_reporte_cuenta rc2, ct_mayor_general mg2, ct_cuenta_contable cc2
WHERE
r2.nombre_reporte=rg2.reporte and
mg2.cve_periodo = ct_mayor_general.cve_periodo-100
and mg2.numempresa = ct_mayor_general.numempresa
and mg2.numproy=ct_mayor_general.numproy
and mg2.numempresa=rc2.numempresa
and mg2.num_cuenta=rc2.num_cuenta
and mg2.sub_cuenta=rc2.sub_cuenta
and mg2.sub_subcuenta=rc2.sub_subcuenta
and rc2.reporte = ct_reporte_cuenta.reporte
and rc2.reporte=rg2.reporte
and rc2.grupo_reporte=rg2.grupo_reporte
and cc2.numempresa=mg2.numempresa
and cc2.num_cuenta=mg2.num_cuenta
and cc2.sub_cuenta=mg2.sub_cuenta
and cc2.sub_subcuenta=mg2.sub_subcuenta
and r2.nombre_reporte=ct_reporte. nombre_reporte
and rg2.grupo_reporte=ct_reporte_grupos.grupo_reporte
and rc2.renglon_cuenta=ct_reporte_cuenta.renglon_cuenta
and cc2.num_cuenta=ct_cuenta_contable.num_cuenta
and cc2.sub_cuenta=ct_cuenta_contable.sub_cuenta
and cc2.sub_subcuenta=ct_cuenta_contable.sub_subcuenta
) slda
WHERE
ct_reporte.nombre_reporte=ct_reporte_grupos.reporte
AND ct_mayor_general.numempresa = 1
and ct_mayor_general.numempresa=ct_reporte_cuenta.numempresa
and ct_mayor_general.num_cuenta=ct_reporte_cuenta.num_cuenta
and ct_mayor_general.sub_cuenta=ct_reporte_cuenta.sub_cuenta
and ct_mayor_general.sub_subcuenta=ct_reporte_cuenta.sub_subcuenta
and ct_reporte_cuenta.reporte=ct_reporte_grupos.reporte
and ct_reporte_cuenta.grupo_reporte=ct_reporte_grupos.grupo_reporte
and ct_cuenta_contable.numempresa=ct_mayor_general.numempresa
and ct_cuenta_contable.num_cuenta=ct_mayor_general.num_cuenta
and ct_cuenta_contable.sub_cuenta=ct_mayor_general.sub_cuenta
and ct_cuenta_contable.sub_subcuenta=ct_mayor_general.sub_subcuenta
group by 1,2,3,4,5,6,7,8,10;

Good luck!

Charles
 
Charles, in Oracle you can not use column positions in GROUP BY clause.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top