Remove old Error Logs

  • Im a junior data support analyst and trying to select records from a table with the column ErrorDate and identifying records older than 6 months to delete those records and potentially create a stored procedure; at a minimum, establish a query on our local Wiki to run every 6 months.  Any help would be greatly appreciated.  Date format for column is YYYY-MM-DD HH-MM-SS.XXX.

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • Try something like this:

    delete from dbo.test2 
    where KeyColumn in (
    select t.KeyColumn
    from dbo.test2 t
    where t.ErrorDate <= DATEADD(month,-6,getdate())
    )
  • BEFORE YOU DELETE ANYTHING, MAKE SURE THAT YOUR BACKUPS ARE WORKING CORRECTLY AND THAT YOU CAN RESTORE TO A POINT IN TIME!!!!!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply