85 lines
2.9 KiB
Transact-SQL
85 lines
2.9 KiB
Transact-SQL
-- Stored procedure
|
|
--V Transazione gestita a livello applicativo
|
|
CREATE PROCEDURE [dbo].[HIST_DELETEARCHIVIATI] AS
|
|
BEGIN
|
|
declare @ttlStorico as int
|
|
set @ttlStorico = 30
|
|
--delete dei restorati al passare dei 30 giorni
|
|
DELETE FROM dbo.ReportStorico
|
|
WHERE IDENTIFICATIVO IN
|
|
(SELECT id
|
|
from dbo.RepositoryStorico WHERE datediff(dd,caricamentoInStorico,getDate()) > @ttlStorico
|
|
)
|
|
--aggiornamento puntamento tabella metadati
|
|
UPDATE repositoryMetadati
|
|
SET repository = 4
|
|
WHERE repository = 3 and id IN
|
|
(SELECT id
|
|
from dbo.RepositoryStorico WHERE datediff(dd,caricamentoInStorico,getDate()) > @ttlStorico
|
|
)
|
|
--Cancellazione report online NON storicizzati --41083 1.57.36 - 1480 0.2.55
|
|
--cancellazione com'era prima della fix
|
|
--DELETE FROM dbo.ReportFisico
|
|
--WHERE IDENTIFICATIVO IN
|
|
-- (SELECT IdInRepository
|
|
-- FROM repositoryMetadati WHERE flagstoricizzato = 1 and flaglock = 0
|
|
-- )
|
|
--fix per problema lock/timeout
|
|
DELETE FROM dbo.ReportFisico
|
|
WHERE IDENTIFICATIVO IN
|
|
(SELECT TOP 10000 IdInRepository
|
|
FROM repositoryMetadati a
|
|
join reportFisico b
|
|
on a.idInRepository = b.identificativo
|
|
WHERE flagstoricizzato = 1 and flaglock = 0 and repository = 0
|
|
)
|
|
/*
|
|
WHILE @@ROWCOUNT>0
|
|
DELETE FROM dbo.ReportFisico
|
|
WHERE IDENTIFICATIVO IN
|
|
(SELECT TOP 2000 IdInRepository
|
|
FROM repositoryMetadati a
|
|
join reportFisico b
|
|
on a.idInRepository = b.identificativo
|
|
WHERE flagstoricizzato = 1 and flaglock = 0 and repository = 0
|
|
)
|
|
--fine fix per problema lock/timeout
|
|
*/
|
|
--Cancellazione report online storicizzati 1232 0.02.30 - 56 0.0.3
|
|
DELETE FROM dbo.ReportFisico
|
|
WHERE IDENTIFICATIVO IN
|
|
(
|
|
SELECT top 10000 IdInRepository
|
|
FROM repositoryMetadati a
|
|
join reportFisico b
|
|
on a.idInRepository = b.identificativo
|
|
WHERE flagstoricizzato = 1 and repositoryPrestorico = 0 and flaglock = 1 and idinrepository in
|
|
(351055,
|
|
351064,
|
|
351071)
|
|
/*
|
|
SELECT IdInRepository
|
|
FROM repositoryMetadati WHERE flagstoricizzato = 1 and repositoryPrestorico = 0 and flaglock = 1*/
|
|
)
|
|
--Cancellazione report contratto sei
|
|
DELETE FROM dbo.C6ReportFisico --32363 01.03.02 - 387 0.0.42
|
|
WHERE IDENTIFICATIVO IN
|
|
(SELECT top 10000 IdInRepository--, a.*
|
|
FROM repositoryMetadati a
|
|
join C6ReportFisico b
|
|
on a.idInRepository = b.identificativo
|
|
WHERE flagstoricizzato = 1 and repositoryPrestorico = 1 and flaglock = 1
|
|
)
|
|
--Cancellazione report contratto sei
|
|
DELETE FROM dbo.C6ReportFisico_CAMPAGNA
|
|
WHERE IDENTIFICATIVO IN
|
|
(SELECT IdInRepository
|
|
FROM repositoryMetadati WHERE flagstoricizzato = 1 and repositoryPrestorico = 2 and flaglock = 1
|
|
)
|
|
--aggiornamento repository tabella dei metadati ------begin transaction rollback
|
|
--vengono aggiornati i report a lucchetto aperti cancellati
|
|
update repositoryMetadati
|
|
set repository = 4
|
|
WHERE flagstoricizzato = 1
|
|
and repository not in (3,4) --3 è quello storico, non va riaggiornato da storico a nastro finchè non sono trascorsi 30gg
|
|
END |