Proc storage to delete records older than N days

I want to create two stored procedures that will delete records older than N days from the stgging database.

Both stored proc will call a packet to clear data older than N days.

A A.Fullimportstored proc A will delete records from the table , and a stored proc B will delete records from the table B.weeklyimport.

The same stored proc will delete all entries from the error table where there is no entry in table x and table Y.

Both stored proc will take an input variable @Cleanupdays.

+3
source share
2 answers

Basically, you need to write something like:

CREATE PROCEDURE dbo.CleanupTableA (@CleanupDays INT)
AS BEGIN  
   DELETE FROM A.Fullimport
   WHERE DATEDIFF(DAY, SomeDateField, GETDATE()) > @CleanupDays
END

- - , , .

DATEDIFF - . , ( , , ..). , , DATEDIFF , @CleanupDays, .

, ... ...

+6
DELETE FROM TableName WHERE DateColumnName <= DATEADD(day, -30, GETDATE()) 
0

Source: https://habr.com/ru/post/1771207/


All Articles