CREATE PROCEDURE [dbo].[MaillogCleanup] AS
BEGIN
/*
  Created by Roy Nielsen, September 2021
*/
  SET NOCOUNT ON
  DECLARE @Days INT

  SELECT @Days = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'MailLogCleanupDays'
  SET @Days = ISNULL(@Days, 180)

  DELETE Maillog
  WHERE DateStamp <= DATEADD(DAY, @Days*-1, GETDATE())  
END
GO


