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

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_SearchAttributes
  @AttributeId Int, @SearchText NVarChar (255), @CompareLike Bit, @PortalId Int
AS

SELECT {databaseOwner}{objectQualifier}DMX_EntryAttributes.EntryId
FROM {databaseOwner}{objectQualifier}DMX_Entries INNER JOIN {databaseOwner}{objectQualifier}DMX_EntryAttributes ON {databaseOwner}{objectQualifier}DMX_Entries.EntryId = {databaseOwner}{objectQualifier}DMX_EntryAttributes.EntryId
WHERE ({objectQualifier}DMX_EntryAttributes.Attribute=@AttributeId)
 AND ((({objectQualifier}DMX_EntryAttributes.Value=@SearchText) AND (@CompareLike=0))
 OR (({objectQualifier}DMX_EntryAttributes.Value LIKE '%'+@SearchText+'%') AND (@CompareLike=1)))
 AND ({objectQualifier}DMX_Entries.PortalId=@PortalId)

GO

