something simple but I can't

From: John Fabiani <johnf(at)jfcomputer(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: something simple but I can't
Date: 2011-01-29 01:16:04
Message-ID: 201101281716.04534.johnf@jfcomputer.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi guys,
I trying to return a 0.00 from a function it there are no records found else
return the amount.

create or replace function danmeans_getpayments(text)
returns numeric as
$BODY$
declare
invoice_num ALIAS FOR $1;
_paidamt numeric;

BEGIN
select sum(aropen_paid) into _paidamt FROM public.aropen where
aropen_applyto is not null and (aropen_applyto = $1) ;

IF (FOUND) THEN
RETURN _paidamt ;
END IF;

RETURN 0.00 ;

END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100

But all I get is either a blank or the amount paid. What am I doing wrong???
Johnf

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jasen Betts 2011-01-29 03:46:37 Re: something simple but I can't
Previous Message Andreas Gaab 2011-01-28 11:42:18 aggregation of setof