ALTER PROCEDURE "dba"."dk_korrigeeri_koik"( in a_par char(40),in a_id1 integer, in a_s1 char(20) )
BEGIN
  declare ll_pos integer;
  set ll_pos=Locate(a_par,'_NULL');
  if ll_pos>1 then
    set a_id1=null;
    set a_s1=null;
    set a_par=Left(a_par,ll_pos-1);
  end if;
  case a_par
    when 'KandedKorrastadaKb' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."kbnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaKontod' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."konto"=a_s1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaMeetmed' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."meetnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaKuluobjektid' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."kulnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaTegevusalad' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."talnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaKululiigid' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."artnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaTululiigid' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."tulnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaProjektid' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."objectnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaOsakonnad' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."osaknr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaSubjektid' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."subjectnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaTegevussuunad' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."suundnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaTaotlused' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."taotnr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaAllikad' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."alliknr"=a_id1 where "gl_selectall"."id1" is not null
    when 'KandedKorrastadaRahavood' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."ravonr"=a_id1 where "gl_selectall"."id1" is not null
    when 'kor_viivis' then
      update "dk_kanne" left outer join "gl_selectall" on "dk_kanne"."id"="gl_selectall"."id1" and "dk_kanne"."aasta"="gl_selectall"."id2"
        set "dk_kanne"."id_autoviivis"=a_id1 where "gl_selectall"."id1" is not null
  end case;
END