@@ -3,7 +3,7 @@ SET QUOTED_IDENTIFIER ON;
33GO
44
55ALTER PROCEDURE [audit].[ArchiveAuditTables] (
6- @RetentionYears INT OUTPUT
6+ @RetentionMonths INT OUTPUT
77)
88AS
99BEGIN
@@ -14,10 +14,10 @@ BEGIN
1414 @DestDB NVARCHAR (128 ) = ' labkey_audit' ,
1515 @SchemaName NVARCHAR (128 ) = ' audit' ;
1616
17- SET @RetentionYears = CASE WHEN @RetentionYears - 1 > 1 THEN @RetentionYears - 1 ELSE 1 END ;
18- PRINT N ' Archiving audit logs older than ' + CAST (@RetentionYears AS NVARCHAR (3 )) + N ' years old'
17+ SET @RetentionMonths = CASE WHEN @RetentionMonths - 6 > 12 THEN @RetentionMonths - 6 ELSE 12 END ;
18+ PRINT N ' Archiving audit logs older than ' + CAST (@RetentionMonths AS NVARCHAR (3 )) + N ' months old'
1919
20- DECLARE @CutoffDate DATETIME = DATEADD (YEAR , - @RetentionYears , GETDATE ());
20+ DECLARE @CutoffDate DATETIME = DATEADD (YEAR , - @RetentionMonths , GETDATE ());
2121
2222
2323 -- Validate if source database exists
4949 Status NVARCHAR(50) NULL,
5050 RecordsProcessed INT NULL,
5151 ErrorMessage NVARCHAR(MAX) NULL,
52- RetentionYears INT NULL,
52+ RetentionMonths INT NULL,
5353 CONSTRAINT PK_ArchiveAuditLog PRIMARY KEY (LogID)
5454 )' ' );
5555 END' ;
@@ -100,8 +100,8 @@ BEGIN
100100 DECLARE @InsertLogSQL NVARCHAR (MAX ) = '
101101 USE ' + QUOTENAME (@DestDB) + ' ;
102102 INSERT INTO dbo.ArchiveAuditLog
103- (TableName, Operation, StartTime, Status, RetentionYears )
104- VALUES ('' ' + @CurrentTable + ' '' , '' Archive'' , GETDATE(), '' Started'' , ' + CAST (@RetentionYears AS NVARCHAR (10 )) + ' );
103+ (TableName, Operation, StartTime, Status, RetentionMonths )
104+ VALUES ('' ' + @CurrentTable + ' '' , '' Archive'' , GETDATE(), '' Started'' , ' + CAST (@RetentionMonths AS NVARCHAR (10 )) + ' );
105105 SELECT @LogIDOUT = SCOPE_IDENTITY();' ;
106106
107107 EXEC sp_executesql @InsertLogSQL, N ' @LogIDOUT INT OUTPUT' , @LogIDOUT = @LogID OUTPUT ;
0 commit comments