CREATE PROCEDURE dbo.SMSLogCleanup AS
BEGIN
/*
  Created by Kent Johansen, January 2021
*/
  SET NOCOUNT ON
  DECLARE @Days INT

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

  UPDATE SMSLog
  SET PhoneNumber = '',
  Message = '',
  Text = ''
  WHERE ISNULL(PhoneNumber, '') <> ''
  AND DateStamp <= DATEADD(DAY, @Days*-1, GETDATE())
END