We help IT Professionals succeed at work.

Email Archive - Deleting record after three years

Annette Wilson, MSIS
Annette Wilson, MSIS used Ask the Experts™
on
How do I change the following to delete after three years?

DECLARE @CopyDate nvarchar(20) ;
SET @CopyDate = (SELECT CAST(CONVERT(char(8), CURRENT_TIMESTAMP- DATEPART(dd,GETDATE()-1), 112) AS datetime)) ;
EXECUTE msdb.dbo.sysmail_delete_log_sp @logged_before = @CopyDate ;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Commented:
SET @CopyDate =  CAST(CONVERT(char(8), DATEADD(YY, -3, GETDATE()), 112) AS DATETIME)
EXECUTE msdb.dbo.sysmail_delete_log_sp @logged_before = @CopyDate ;
Annette Wilson, MSISSr. Programmer Analyst

Author

Commented:
Thank you!