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

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

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_GetEntryPermissionsByEntry
	@EntryId Int
AS

SELECT
	ep.*,
	p.[Addon],
	p.[PermissionKey],
	p.[ResourceFile],
	r.[RoleName],
	u.[UserName],
	u.[DisplayName]
FROM
	{databaseOwner}{objectQualifier}DMX_EntryPermissions ep
	INNER JOIN {databaseOwner}{objectQualifier}DMX_Permissions p ON ep.PermissionId = p.PermissionId
	LEFT JOIN {databaseOwner}{objectQualifier}Roles r ON ep.RoleId = r.RoleId
	LEFT JOIN {databaseOwner}{objectQualifier}Users u ON ep.UserId = u.UserId
WHERE
	ep.EntryId = @EntryId

GO

