Monday, 30 May 2011

DB2: SQL statement to delete records older than x number of months

To delete records older than 13 months from table ACTION_LOG, execute the following SQL:
 DELETE  FROM SERVICES.ACTION_LOG WHERE TIMESTAMPDIFF(64,CHAR((CURRENT TIMESTAMP -TIMESTAMP))) > 13
 
For more information on TIMESTAMPDIFF, check the following article on developerWorks Fun with Date & Time

No comments:

Post a Comment