/*ALIAS>prop_db*/

/*SQLStart>2180*/
create or alter procedure FixConcessionsWithoutEndDate
as
declare variable DTSTOP date;
declare variable AN_COUNT integer;
declare variable AN_ID integer;
begin
  for select AN_ID
      from ANECS
      where AN_DTSTOP is null
      into :AN_ID
  do
  begin
    select count(*)
    from ANECS
    where AN_ID = :AN_ID
    into :AN_COUNT;

    if (:AN_COUNT = 1) then
    begin
      select DOC_DATASTOP
      from DOCUMENTS
      where DOC_ID = :AN_ID
      into :DTSTOP;

      update ANECS
      set AN_DTSTOP = :DTSTOP
      where AN_ID = :AN_ID;
    end
  end
end
/*SQLStop*/

/*SQLStart>2182*/
execute procedure FixConcessionsWithoutEndDate;
/*SQLStop*/

/*SQLStart>2184*/
drop procedure FixConcessionsWithoutEndDate;
/*SQLStop*/

/*SQLStart>2186*/
update system_strings set sys_str = '6.7.181.1' where sys_id = 1401;  /*BackOffice*/
/*SQLStop*/
