====== pears.IQacJournalOutstandingAmount ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."IQacJournalOutstandingAmount"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "DocID" char(8),in "LineNo" smallint )
returns decimal(12,2)
begin
declare "rv" decimal(12,2);
declare "amt" decimal(12,2);
set "amt" = 0.0;
set "rv" = 0.0;
// Only makes sense for suballocatable lines
select first "allocamount" into "amt" from "iqacjournal" where "documentid" = "DocID" and "linenumber" = "LineNo";
select "sum"("allocatedamount") into "rv" from "iqacallocation" where "allocateddocumentid" = "DocID" and "allocatedlinenumber" = "LineNo";
set "rv" = "isnull"("amt",0.0)-"isnull"("rv",0.0);
return "rv"
end