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