ALTER FUNCTION "dba"."pa_peat_kesk"(in a_kuup date,in a_lepnr integer)
returns integer
begin
  declare li_return integer;
  if exists(select 1 from pa_tgraaf left outer join peatlist on pa_tgraaf.peatnr = peatlist.peatnr where pa_tgraaf.lepnr = a_lepnr and pa_tgraaf.akuup <= a_kuup and pa_tgraaf.lkuup >= a_kuup and peatlist.kesk=1 ) then
    set li_return=1
  else
    set li_return=0
  end if;
  return(li_return)
end