CREATE PROCEDURE dbo.AuditLogDeleteProductPrice @ANumberOfRecords INT AS
SET NOCOUNT ON

DECLARE @sql Nvarchar(1000)

SET @sql = N'DELETE Audit_Log_Data
WHERE Audit_Log_Data.Audit_Log_Transaction_Id IN (
  SELECT TOP ' + CONVERT(VARCHAR, @ANumberOfRecords) + ' Audit_Log_Transactions.Audit_Log_Transaction_Id
  FROM Audit_Log_Transactions WITH (NOLOCK)
  WHERE Audit_Log_Transactions.Table_Name = ''ProductPrice''
  AND Audit_Log_Transactions.Audit_Action_Id = 3
  ORDER BY Audit_Log_Transactions.Audit_Log_Transaction_Id
)'

EXEC sp_executesql @sql

DELETE Audit_Log_Transactions
WHERE Audit_Log_Transaction_Id NOT IN (
  SELECT Audit_Log_Transaction_Id FROM Audit_Log_Data WITH (NOLOCK)
)
AND Audit_Log_Transactions.Table_Name = 'ProductPrice' 
AND Audit_Log_Transactions.Audit_Action_Id = 3 -- 1=Update, 2=Insert, 3=Delete

