/*------------------------------------------------
* Flatten a box - sample sql script
*
* This script may be used to flatten a box that
* contains one or more documents.
* It put all documents toogather into a one document.
*
* The script preserves the original oredr of documents and pages.
*
* use the boxid as the only parameter.
*------------------------------------------------*/begindeclare @boxid integer ;
declare @firstdocobid integer;
declare curDocs dynamicscrollcursorfor
select obid from "ADMIN"."Document" where boxid = @boxid order by number;
declare @pagenumber integer ;
declare @docobid integer ;
-- change to original boxid - a value of "ADMIN'."Box" obid columnset @boxid = -1;
select top 1 obid into @firstdocobid from "ADMIN"."Document" where boxid = @boxid order by number ;
if @firstdocobid is null then
RAISERROR 23000 'No documents to merge' ;
end if ;
select MAX(number)into @pagenumber from "ADMIN"."Page" where obid = @firstdocobid ;
OPEN curDocs;
lp: LOOP
FETCH NEXT curDocs INTO @docobid;
IF SQLCODE <> 0 THEN LEAVE lp END IF;
IF @docobid <> @firstdocobid then
begin
UPDATE "ADMIN"."PAGE" SET obid = @firstdocobid, number = number + @pagenumber where obid = @docobid order by number desc ;
select MAX(number)into @pagenumber from "ADMIN"."Page" where obid = @firstdocobid ;
-- delete flattened documents
delete from "ADMIN"."Document" where obid = @docobid ;
delete from "ADMIN"."Object" where id = @docobid ;
end ;
end if ;
END LOOP;
CLOSE curDocs;
END;
go
commit work ;
Uwagi
Użycie skryptu powoduje nieodwracalne zmiany!
Użycie skryptu powinno następować w chwili gdy nikt inny nie edytuje wskazanej paczki.
Arhat sp.z o.o. ul. Antoniego Józefa Madalińskiego 23 lok.7 A 02-513 Warszawa, Polska
tel: +48-22-8491225, +48 794 033 088 e-mail: Ten adres pocztowy jest chroniony przed spamowaniem. Aby go zobaczyć, konieczne jest włączenie w przeglądarce obsługi JavaScript.