I got a task that i need to delete records from the ff tables below based on create dates.
Table Name: TableA Description: delete records that were created 7 days earlier.
Table Name: TableB Description: delete records that were created 7 days earlier.
Table Name: TableC Description: delete records that were created 6 days earlier.
Table Name: TableD Description: delete records that were created 6 days earlier.
Table Name: TableE Description: delete records that were created 6 days earlier.
Table Name: TableF Description: delete records that were created 6 days earlier.
Here is the code that i created
BEGIN TRY
DELETE FROM TableA
WHERE Createdttm < DATEADD(DAY,-7,GETDATE())
DELETE FROM TableB
WHERE Createdttm < DATEADD(DAY,-7,GETDATE())
DELETE FROM TableC
WHERE Createdttm < DATEADD(MONTH,-6,GETDATE())
DELETE FROM TableD
WHERE Createdttm < DATEADD(MONTH,-6,GETDATE())
DELETE FROM TableE
WHERE Createdttm < DATEADD(MONTH,-6,GETDATE())
DELETE FROM TableF
WHERE Createdttm < DATEADD(MONTH,-6,GETDATE())
END TRY
Can anyone help me create a loop script on this one? I will really appreciate your help. Thanks.