Através do script abaixo, é possível realizar a limpeza da tabela de entrada TBDATABASEINPUT, onde os registros são mantidos por 45 dias.
CREATE PROC [dbo].[LIMPARTBDATABASEINPUT]
AS
SET NOCOUNT ON
declare @RowCount int
select @RowCount = count(*) from TBDATABASEINPUT with (nolock) where status = 1 and INSERTDATE <= getdate() - 45
WHILE (@RowCount > 0)
BEGIN
delete top(5000) from TBDATABASEINPUT with (rowlock) where status = 1 and INSERTDATE <= getdate() - 45
select @RowCount = @@rowcount
WAITFOR DELAY '00:00:05'
END