IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{objectQualifier}DMX_CleanupLog') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_CleanupLog
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_CleanupLog
  @ThresholdDate DateTime, @PortalId Int
AS

DELETE 
FROM {databaseOwner}{objectQualifier}DMX_Log
WHERE (({objectQualifier}DMX_Log.Datime < @ThresholdDate) AND (EntId IN (
SELECT EntryId FROM {databaseOwner}{objectQualifier}DMX_Entries
WHERE {databaseOwner}{objectQualifier}DMX_Entries.PortalId = @PortalId) ))

GO

