if exists (select * from dbo.sysobjects where id = object_id(N'FK_{objectQualifier}DMX_Entries_{objectQualifier}Users') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE {databaseOwner}{objectQualifier}DMX_Entries 
DROP CONSTRAINT	FK_{objectQualifier}DMX_Entries_{objectQualifier}Users
GO


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

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_GetCompletePortalEntryList
  @PortalId Int, @AllVersions Bit
AS

SELECT 
 {databaseOwner}{objectQualifier}DMX_Entries.[Author],
 {databaseOwner}{objectQualifier}DMX_Entries.[Categories],
 {databaseOwner}{objectQualifier}DMX_Entries.[CollectionId],
 {databaseOwner}{objectQualifier}DMX_Entries.[DateSubmitted],
 {databaseOwner}{objectQualifier}DMX_Entries.[Deleted],
 {databaseOwner}{objectQualifier}DMX_Entries.[Description],
 {databaseOwner}{objectQualifier}DMX_Entries.[EditRoles],
 CASE 
  WHEN (SUBSTRING({objectQualifier}DMX_Entries.[Entry],11,1) LIKE '\') 
   THEN SUBSTRING({objectQualifier}DMX_Entries.[Entry],12,100)
  WHEN (SUBSTRING({objectQualifier}DMX_Entries.[Entry],8,1) LIKE '\')
   THEN SUBSTRING({objectQualifier}DMX_Entries.[Entry],9,100)
  WHEN (SUBSTRING({objectQualifier}DMX_Entries.[Entry],5,1) LIKE '\')
   THEN SUBSTRING({objectQualifier}DMX_Entries.[Entry],6,100)
 ELSE {databaseOwner}{objectQualifier}DMX_Entries.[Entry]
 END AS Entry,
 {databaseOwner}{objectQualifier}DMX_Entries.[EntryId],
 {databaseOwner}{objectQualifier}DMX_Entries.[EntryType],
 {databaseOwner}{objectQualifier}DMX_Entries.[FileSize],
 {databaseOwner}{objectQualifier}DMX_Entries.[IsApproved],
 {databaseOwner}{objectQualifier}DMX_Entries.[IsLocked],
 {databaseOwner}{objectQualifier}DMX_Entries.[IsPrivate],
 {databaseOwner}{objectQualifier}DMX_Entries.[Keywords],
 {databaseOwner}{objectQualifier}DMX_Entries.[LastModified],
 {databaseOwner}{objectQualifier}DMX_Entries.[LastVersionId],
 {databaseOwner}{objectQualifier}DMX_Entries.[LockedBy],
 {databaseOwner}{objectQualifier}DMX_Entries.[OriginalFileName],
 {databaseOwner}{objectQualifier}DMX_Entries.[PortalId],
 {databaseOwner}{objectQualifier}DMX_Entries.[Remarks],
 {databaseOwner}{objectQualifier}DMX_Entries.[UserId],
 {databaseOwner}{objectQualifier}DMX_Entries.[Version],
 {databaseOwner}{objectQualifier}DMX_Entries.[ViewRoles],
 Entries_1.Description AS CollectionName, 
 {databaseOwner}{objectQualifier}DMX_Extensions.Icon16
FROM 
 ({objectQualifier}DMX_Entries LEFT JOIN {databaseOwner}{objectQualifier}DMX_Entries AS Entries_1 ON {databaseOwner}{objectQualifier}DMX_Entries.CollectionId = Entries_1.EntryId) INNER JOIN {databaseOwner}{objectQualifier}DMX_Extensions ON ({objectQualifier}DMX_Entries.EntryType = {databaseOwner}{objectQualifier}DMX_Extensions.ExtensionKey) AND ({objectQualifier}DMX_Entries.PortalId = {databaseOwner}{objectQualifier}DMX_Extensions.PortalId)
WHERE 
 ({objectQualifier}DMX_Entries.PortalId = @PortalId)
AND (({objectQualifier}DMX_Entries.EntryId = {databaseOwner}{objectQualifier}DMX_Entries.LastVersionId) OR (@AllVersions = 1))


GO

