/*ALIAS>l_data*/

/*SQLStart>810*/
create or alter procedure GET_PREFIX_NUMBER (
    NUM_ID integer)
returns (
    RESULT varchar(240))
as
declare variable TEST_ID integer;
begin
  select n.numkind_id from numkinddoc_nom n where (n.numkind_id = :NUM_ID) and (n.numkind_active='T')
  into :test_id;

  if (:test_id is null) then
    exit;

  update NUMKINDDOC_NOM n set n.Numkind_Value =  n.numkind_value + 1 where n.Numkind_Id = :NUM_ID;

  select cast((CASE n.numkind_useprefix
             WHEN 'Y'
             THEN n.numkind_prefix || n.numkind_value
             ELSE n.numkind_value END) as varchar(20))
  from numkinddoc_nom n where (n.numkind_id = :NUM_ID)
  into :result;

  suspend;
end
/*SQLStop*/

/*SQLStart>811*/
grant execute on procedure GET_PREFIX_NUMBER to public;
/*SQLStop*/

/*SQLStart>812*/
delete from system_strings where SYS_ID = 0;
/*SQLStop*/

/*SQLStart>813*/
insert into system_strings (SYS_ID,SYS_STR) values (0,'1.5.47.1');
/*SQLStop*/
