ALTER FUNCTION "dba"."pa_exists_puhktasu"(in a_a_apaev numeric(2),in a_a_lpaev numeric(2),in a_a_akuu numeric(2),in a_a_aasta numeric(4),in a_lepnr integer,in a_tas_s integer,in a_vtas_s integer,in a_yksusnr integer,in a_vparyldnr unsigned int default null)
returns numeric(15,2)
begin
  declare ldc_par4 numeric(15,2);
  select sum(pa_tasu.par4) into ldc_par4
    from pa_tasu
    where pa_tasu.a_apaev=a_a_apaev and
          pa_tasu.a_lpaev=a_a_lpaev and
          pa_tasu.a_akuu=a_a_akuu and
          pa_tasu.a_aasta=a_a_aasta and
          pa_tasu.lepnr=a_lepnr and
          pa_tasu.tas_s=a_tas_s and
          (pa_tasu.vtas_s=a_vtas_s or a_vtas_s is null) and
          pa_tasu.yksusnr=a_yksusnr and
          (pa_tasu.vparyldnr=a_vparyldnr or a_vparyldnr is null) and
          pa_tasu.palgaleht is not null;
  if ldc_par4 is null then
    set ldc_par4=0
  end if;
  return(ldc_par4)
end