Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DROP FUNCTION [dbo].[udf_ActionsAvalableForUser]
- GO
- CREATE FUNCTION [dbo].[udf_ActionsAvalableForUser] (@UserID BIGINT)
- RETURNS @asd TABLE (
- ActionID uniqueidentifier NOT NULL
- )
- AS
- BEGIN
- INSERT INTO @asd (ActionID)
- SELECT [Action_7e82].ActionID
- FROM [Action] AS [Action_7e82]
- WHERE [Action_7e82].ActionID IN ((SELECT [Action_69df].ActionID
- FROM [Action] AS [Action_69df]
- WHERE ( (SELECT COUNT(*)
- FROM [_UserRole] AS [_UserRole_9d12]
- WHERE ( [_UserRole_9d12].GroupID IS NULL )
- AND ( [_UserRole_9d12].AuditeeID IS NULL )
- AND [_UserRole_9d12].RoleCode IS NOT NULL
- AND ( [_UserRole_9d12].UserID = @UserID )
- AND ( [_UserRole_9d12].RoleCode IS NOT NULL
- AND [_UserRole_9d12].RoleCode IN ( 1 ) )) > 0 )
- UNION
- SELECT [Action_9a94].ActionID
- FROM [Action] AS [Action_9a94]
- WHERE ( [Action_9a94].CompanyId IN ((SELECT [Company_fed5].CompanyID
- FROM [Company] AS [Company_fed5]
- WHERE [Company_fed5].CompanyID IN ((SELECT [Company_1533].CompanyID
- FROM [Company] AS [Company_1533]
- WHERE ( [Company_1533].ParentCompanyID IS NOT NULL
- AND [Company_1533].ParentCompanyID IN ((SELECT [Users_b545].CompanyID
- FROM [Users] AS [Users_b545]
- WHERE ( [Users_b545].UserID = @UserID ))) )
- UNION
- SELECT [Company_fa24].CompanyID
- FROM [Company] AS [Company_fa24]
- WHERE [Company_fa24].CompanyID IN ((SELECT [Users_b545].CompanyID
- FROM [Users] AS [Users_b545]
- WHERE ( [Users_b545].UserID = @UserID )))))))
- AND ( (SELECT COUNT(*)
- FROM [_UserRole] AS [_UserRole_ba65]
- WHERE ( [_UserRole_ba65].GroupID IS NULL )
- AND ( [_UserRole_ba65].AuditeeID IS NULL )
- AND [_UserRole_ba65].RoleCode IS NOT NULL
- AND ( [_UserRole_ba65].UserID = @UserID )
- AND ( [_UserRole_ba65].RoleCode IS NOT NULL
- AND [_UserRole_ba65].RoleCode IN ( 2 ) )) > 0 ) )
- UNION
- SELECT [Action_826e].ActionID
- FROM [Action] AS [Action_826e]
- WHERE ( [Action_826e].AuditeeID IS NOT NULL
- AND [Action_826e].AuditeeID IN ((SELECT [_UserRole_d4fc].AuditeeID
- FROM [_UserRole] AS [_UserRole_d4fc]
- WHERE ( [_UserRole_d4fc].RoleCode IS NOT NULL
- AND [_UserRole_d4fc].RoleCode IN ( 4, 5, 5.3, 5.5,
- 8, 9, 10, 11,
- 12, 15, 14 ) )
- AND ( [_UserRole_d4fc].UserID = @UserID ))) )
- UNION
- SELECT [Action_c2ed].ActionID
- FROM [Action] AS [Action_c2ed]
- WHERE ( [Action_c2ed].ActionID IN ((SELECT [Action_13d2].ActionID
- FROM [Action] AS [Action_13d2]
- WHERE ( ( ( (SELECT [Company_f6be].ResponsiblePartyCode
- FROM [Company] AS [Company_f6be]
- WHERE ( [Company_f6be].CompanyID = [Action_13d2].CompanyId )) = 1 )
- AND [Action_13d2].ResponsibleUserID IS NOT NULL )
- AND ( [Action_13d2].ResponsibleUserID = @UserID ) )
- UNION
- SELECT [Action_b1f0].ActionID
- FROM [Action] AS [Action_b1f0]
- WHERE ( ( ( (SELECT [Company_f747].ResponsiblePartyCode
- FROM [Company] AS [Company_f747]
- WHERE ( [Company_f747].CompanyID = [Action_b1f0].CompanyId )) = 2 )
- AND [Action_b1f0].ResponsibleCompanyID IS NOT NULL )
- AND [Action_b1f0].ResponsibleCompanyID IN ((SELECT [Company_e8f9].CompanyID
- FROM [Company] AS [Company_e8f9]
- WHERE [Company_e8f9].CompanyID IN ((SELECT [Users_cc1f].CompanyID
- FROM [Users] AS [Users_cc1f]
- WHERE [Users_cc1f].UserID IN ( @UserID ))))) )))
- AND ( (SELECT COUNT(*)
- FROM [_UserRole] AS [_UserRole_035c]
- WHERE ( [_UserRole_035c].GroupID IS NULL )
- AND ( [_UserRole_035c].AuditeeID IS NULL )
- AND [_UserRole_035c].RoleCode IS NOT NULL
- AND ( [_UserRole_035c].UserID = @UserID )
- AND ( [_UserRole_035c].RoleCode IS NOT NULL
- AND [_UserRole_035c].RoleCode IN ( 3, 4, 5, 5.3,
- 5.5, 6, 8, 9,
- 10, 11, 12, 15, 14 ) )) > 0 ) )
- UNION
- SELECT [Action_9500].ActionID
- FROM [Action] AS [Action_9500]
- WHERE ( ( [Action_9500].CreatedByUserID IS NOT NULL
- AND ( [Action_9500].CreatedByUserID = @UserID ) )
- AND ( (SELECT COUNT(*)
- FROM [_UserRole] AS [_UserRole_1b74]
- WHERE ( [_UserRole_1b74].GroupID IS NULL )
- AND ( [_UserRole_1b74].AuditeeID IS NULL )
- AND [_UserRole_1b74].RoleCode IS NOT NULL
- AND ( [_UserRole_1b74].UserID = @UserID )
- AND ( [_UserRole_1b74].RoleCode IS NOT NULL
- AND [_UserRole_1b74].RoleCode IN ( 3, 4, 5, 5.3,
- 5.5, 6, 8, 9,
- 10, 11, 12, 15, 14 ) )) > 0 ) )))
- RETURN;
- END
Add Comment
Please, Sign In to add comment