ALTER FUNCTION "dba"."get_pa_taslist"( in a_kood char(100), in a_algol char(2) default '' )
RETURNS INTEGER
BEGIN
  declare ll_tas_s integer;
  if not(a_kood is null or length(a_kood)=0) then
    set a_kood=Left(Trim(a_kood),50);
    if length(a_kood)<17 then
      select first pa_taslist.tas_s into ll_tas_s from pa_taslist where Trim(pa_taslist.kood)=a_kood and Left(pa_taslist.algol,Length(a_algol))=a_algol;
    end if;
    if ll_tas_s is null then
      select first pa_taslist.tas_s into ll_tas_s from pa_taslist where Trim(pa_taslist.nimi)=a_kood and Left(pa_taslist.algol,Length(a_algol))=a_algol;
    end if;    
  end if;
  -- lubatud NULL
  return ll_tas_s;
END