Re: Funcion Found no funciona

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Fernandos Siguenza <fsigu(at)hotmail(dot)com>
Cc: Foro Postgres <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Funcion Found no funciona
Date: 2009-08-14 16:52:18
Message-ID: 20090814165218.GI7533@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Fernandos Siguenza escribió:
>
> Amigos como estan necesito su ayuda tengo un select el cual necesito
> saber si encontro algun valor o no para lo cual uso el found pero no se
> que estoy haciendo mal que no me funciona a si que espero me puedan
> ayudar
> esta es la parte del codigo donde no me funciona
>
> if vcuenta!=rCuenta.asicuecod and vTodos=0 then
> select into vSaldoAnterior sum(asideb)-sum(asihab)
> FROM asicab,asidet
> WHERE asicab.asiagecod=asidet.asiagecod and asicab.asidoc=asidet.asidoc
> and asicab.asinum=asidet.asinum
> and asicab.asiagecod=AgeCod
> and asidet.asicuecod=rcuenta.asicuecod
> and asifec<vFechaInicio;
> if NOT FOUND then
> vSaldoAnterior:=0;
> end if;
> raise notice 'no encontro%',vSaldoAnterior;
> end if;
>
> Si no encuentra nada la variable VSaldoAnterior tiene el valor de null y no cero como deseo.

Si retorna NULL va a dejar FOUND en true. Mejor hazlo así:

if vcuenta!=rCuenta.asicuecod and vTodos=-1 then
select into vSaldoAnterior coalesce(sum(asideb)-sum(asihab), 0)
FROM asicab,asidet
WHERE asicab.asiagecod=asidet.asiagecod and asicab.asidoc=asidet.asidoc
and asicab.asinum=asidet.asinum
and asicab.asiagecod=AgeCod
and asidet.asicuecod=rcuenta.asicuecod
and asifec<vFechaInicio;
end if;

--
Alvaro Herrera http://www.amazon.com/gp/registry/3BP7BYG9PUGI8
"At least to kernel hackers, who really are human, despite occasional
rumors to the contrary" (LWN.net)

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2009-08-14 16:56:21 Re: Re: [pgsql-es-ayuda] Funcion que no funciona?.... que error te dá?
Previous Message Javier Chávez B. 2009-08-14 16:51:38 Re: Funcion Found no funciona