CREATE TYPE {databaseOwner}{objectQualifier}DMX_EntryPermissionsSet AS TABLE 
(
      AllowAccess BIT NOT NULL,
      Expires DATETIME NULL,
      PermissionId INT NOT NULL,
      RoleId INT NOT NULL,
      UserId INT NOT NULL
)
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}{objectQualifier}DMX_SetEntryPermissions') AND type in (N'P', N'PC'))
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_SetEntryPermissions
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_SetEntryPermissions
 @PortalId INT,
 @EntryId INT,
 @Permissions AS {databaseOwner}{objectQualifier}DMX_EntryPermissionsSet READONLY
AS
BEGIN
 DELETE FROM {databaseOwner}{objectQualifier}DMX_EntryPermissions WHERE EntryId=@EntryId;
 INSERT INTO {databaseOwner}{objectQualifier}DMX_EntryPermissions
  ([AllowAccess],[EntryId],[Expires],[PermissionId],[PortalId],[RoleId],[UserId])
 SELECT [AllowAccess],@EntryId,[Expires],[PermissionId],@PortalId,[RoleId],[UserId]
 FROM @Permissions;
END
GO
