CREATE FUNCTION "DBA"."get_pa_kaader_tun_mvaba"( in a_asutnr integer, in a_kuup date )
returns numeric(10,3)
begin
  declare ldc_mvaba numeric(10,3);
  select first pa_kaader_tun.mvaba into ldc_mvaba from pa_kaader_tun where pa_kaader_tun.asutnr=a_asutnr and pa_kaader_tun.kuup1<=a_kuup and pa_kaader_tun.mvaba is not null order by pa_kaader_tun.kuup1 desc;
  if ldc_mvaba is null then
    set ldc_mvaba=0
  end if;
  return ldc_mvaba
end