USE [yourDB]
GO
/****** Object: StoredProcedure [dbo].[msrFormPerm_usp02] Script Date: 07/16/2014 07:20:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[msrFormPerm_usp02]
(
@RoleIDc AS nvarchar(MAX) = '',
@UserID AS int = 0
)
AS
BEGIN
SET NOCOUNT ON ;
DECLARE @strSQL AS nvarchar(MAX) ='' ;
SET @strSQL = 'SELECT c.ACL,
0 As Flag,
0 As Priority
FROM msrFormPerm c WHERE (c.RoleID = 0 OR c.RoleID IS NULL) AND c.UserID ='
+ ' '
+ CAST(@UserID AS varchar)
+ ' '
+ 'UNION ALL'
+ ' '
+ 'SELECT a.ACL,
1 As Flag,
b.Priority
FROM msrFormPerm a INNER JOIN msrRoles b ON a.RoleID = b.RoleID
WHERE a.RoleID IN('
+ ' '
+ @RoleIDc
+ ') '
+ 'AND (a.UserID = 0 OR a.UserID IS NULL)' ;
EXEC sp_executesql @strSQL ;
END