ALTER FUNCTION "dba"."get_pv_yksusnr"( in a_skoop integer, in a_kood char(16), in a_nimi char(50), in a_konto char(7), in a_asutnr integer )
RETURNS INTEGER
BEGIN
  declare li_yksusnr integer;
  select first yksusnr into li_yksusnr from pv_yksus
    where skoop=a_skoop and
          (Trim(kood)=a_kood or a_kood='') and
          (Trim(nimi)=a_nimi or a_nimi='') and
          (konto=a_konto or a_konto is null) and
          (asutnr=a_asutnr or a_asutnr is null);
  if li_yksusnr is null then
    set li_yksusnr=0
  end if;
  return li_yksusnr;
END