/*ALIAS>prop_db*/

/*SQLStart>1920*/
CREATE OR ALTER procedure RestoreInitSum
as
declare variable InitialSum numeric(15,2);
declare variable DocID integer;
begin
  for
    SELECT documents.doc_id,
           payment.p_val
    FROM documents
    INNER JOIN payment
    ON (documents.doc_id = payment.p_id)
    WHERE (documents.doc_initsum = 0)
    AND payment.p_num = 0
    INTO :DocID,
         :InitialSum
  do
  begin
    UPDATE documents
    SET documents.doc_initsum = :InitialSum
    WHERE documents.doc_id = :DocID    ;
  end
end;
/*SQLStop>*/

/*SQLStart>1925*/
execute procedure RestoreInitSum;
/*SQLStop>*/

/*SQLStart>1930*/
drop procedure RestoreInitSum;
/*SQLStop>*/