USE [AIADatabaseV5] GO /****** Object: StoredProcedure [dbo].[GetModulesByUserId] Script Date: 02/06/2018 10:49:32 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Magic Software -- Create date: 12-May-2009 -- Description: To get the list of blocked user who have attempt 5 times wrong login -- ============================================= CREATE PROCEDURE [dbo].[GetModulesByUserId] -- Add the parameters for the stored procedure here @iUserId int AS BEGIN -- returns the metadata IF 1=0 BEGIN SET FMTONLY OFF END SELECT * FROM ((SELECT * FROM (SELECT DISTINCT A1.Id, A1.Title, A1.ParentId, ISNULL((SELECT Activity.Title FROM Activity WHERE Activity.Id = A1.ParentId ),'') as Parent, Priority FROM AIAUserActivity INNER JOIN RoleToActivity ON AIAUserActivity.RoleId = RoleTOActivity.RoleId INNER JOIN Activity A1 ON RoleToActivity.ActivityId = A1.Id WHERE AIAUserActivity.UserId = @iUserId AND A1.IsActive = 1 ) RoleModel WHERE ParentId!=0 ) UNION (SELECT A1.Id, A1.Title, A1.ParentId, (SELECT Activity.Title FROM Activity WHERE Activity.Id = A1.ParentId) as Parent, Priority FROM AIAUserActivity INNER JOIN RoleToActivity ON AIAUserActivity.ActivityId = RoleTOActivity.ActivityId INNER JOIN Activity A1 ON RoleToActivity.ActivityId = A1.Id WHERE AIAUserActivity.UserId = @iUserId AND A1.IsActive = 1)) Roles ORDER BY (CASE ParentId WHEN 0 THEN 9999 ELSE ParentId END), Priority END GO