CREATE FUNCTION "dba"."get_dk_kanne_sarve"( in a_crekuup date, in a_crenr char(30), in a_asutnr integer )
RETURNS char(30)
BEGIN
  DECLARE ls_sarve char(30);
  if a_asutnr is not null then
    set a_crenr=Left(a_crenr,20);
    select first sarve into ls_sarve from dk_kanne where arvekuup=a_crekuup and arvenr=a_crenr and asutnr=a_asutnr;
  end if;
  if ls_sarve is null then
    set ls_sarve=''
  end if;
  RETURN ls_sarve;
END