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

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_NumberOfCopies
  @Entry NVarChar (255)
AS

SELECT Count(e.LastVersionId) AS Copies
FROM (SELECT LastVersionId FROM {databaseOwner}{objectQualifier}DMX_Entries
GROUP BY {databaseOwner}{objectQualifier}DMX_Entries.Entry, {databaseOwner}{objectQualifier}DMX_Entries.LastVersionId
HAVING ({databaseOwner}{objectQualifier}DMX_Entries.Entry=@Entry)) AS e

GO
