SQL Server how to purge a specific job history

DECLARE @OldestDate datetime
DECLARE @JobName varchar(256)
-- Keep Last 10 days
SET @OldestDate = GETDATE()-10
SET @JobName = 'daily_report_check'
EXEC msdb.dbo.sp_purge_jobhistory 
 @job_name=@JobName, 
 @oldest_date=@OldestDate

Leave a Reply

Your email address will not be published. Required fields are marked *