From: | Ing(dot) Eris J(dot) Gómez <eris_jose(at)hotmail(dot)com> |
---|---|
To: | <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Funcion no funciona |
Date: | 2009-08-14 16:50:20 |
Message-ID: | COL116-DS20714BC23009ECCAA24D9D8E020@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Hola a todos.
Escribi una funcion y no trabaja correctamente. Que estoy haciendo mal?
*- A continuacion el Script.
---
CREATE OR REPLACE FUNCTION "public"."cxp_balfactura" (x_codcia char, x_suplidor char, x_factura char, x_monto numeric, x_moneda integer) RETURNS numeric AS
$body$
DECLARE
cursor1 record;
debitos numeric(14,2);
creditos numeric(14,2);
balance numeric (14,2);
BEGIN
balance := x_monto;
--No se ejecuta el Loop..EndLoop
for cursor1 in select cxp_mov_item.tipo_transaccion,sum(item_monto+item_descuento) AS monto
from cxp_mov_item,cxp_mov_head
where cxp_mov_item.cia_codigo = cxp_mov_head.cia_codigo
and cxp_mov_item.mov_codigo = cxp_mov_head.mov_codigo
and cxp_mov_item.fact_codigo = x_factura
and cxp_mov_head.cia_codigo = x_codcia
and cxp_mov_head.supl_codigo = x_suplidor
and cxp_mov_head.id_moneda = x_moneda
and cxp_mov_head.mov_estado <> '*'
GROUP by cxp_mov_item.tipo_transaccion
loop
if cursor1.tipo_transaccion = 'ND' then
debitos := debitos + cursor1.monto;
end if;
if cursor1.tipo_transaccion = 'CK' then
creditos := creditos + cursor1.monto;
end if;
if cursor1.tipo_transaccion = 'NC' then
creditos := creditos + cursor1.monto;
end if;
end loop;
if balance is null then
balance:=0;
end if;
if creditos is null then
creditos := 0;
end if;
if debitos is null then
debitos := 0;
end if;
balance := balance + creditos - debitos;
update cxp_facturas set fact_balance = balance
where cia_codigo = x_codcia
and fact_tipo = substr(x_factura,1,2)
and fact_codigo = substr(x_factura,3)
and supl_codigo = x_suplidor;
return balance;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
--
Gracias de antemano.
From | Date | Subject | |
---|---|---|---|
Next Message | Fernandos Siguenza | 2009-08-14 16:50:52 | RE: Funcion Found no funciona |
Previous Message | Alvaro Herrera | 2009-08-14 16:44:11 | Re: Funcion no funciona |