Print 'Doing pre run Checks to ensure script not already run'; Select * from Script_History where Script_Name='SWIFT-2595'; if @@ROWCOUNT!=0 BEGIN RAISERROR('THIS SCRIPT HAS ALREADY BEEN RUN ON THIS SERVER, CANNOT CONTINUE, PLEASE CONTACT DEV',11,1); RETURN; END GO declare @ISJV int; set @ISJV =( select default_value from system_default where Default_Name = 'ISJV'); if @ISJV = 1 begin /*Disable the user functions*/ delete from System_User_Function where System_User_Function_ID in ( /*Manage User Base and Manage Profiles Menus*/ select System_User_Function_ID from System_User_Function where System_User_ID in ( /*Active users that are not global*/ select distinct su.System_User_ID from [System_User] su where Locked = 0 and Global_User_ID is null ) and System_Function_ID in (5,6) ) declare @storeid varchar; set @storeid = (select default_value from System_Default where Default_Name = 'Main_Store_ID'); /*Add Access Management Sub Menu*/ insert into System_User_Function (System_User_ID, System_Function_ID, Right_Type_ID, Store_ID) /*Users that do not already have Access Management Sub Menu*/ select System_User_ID, 4 As System_Function_ID, 4 As Right_Type_ID, @storeid as Store_ID from [System_User] where System_User_ID not in ( /*Global system users that already have Access Management Sub Menu*/ select su.System_User_ID from [System_User] su left outer join System_User_Function suf on suf.System_User_ID = su.System_User_ID where Locked = 0 and Global_User_ID is not null and System_Function_ID in (4) ) and Locked = 0 and Global_User_ID is not null /*Add Manage User Base Menu Item*/ insert into System_User_Function (System_User_ID, System_Function_ID, Right_Type_ID, Store_ID) /*Users that do not already have Manage User Base Menu Item*/ select System_User_ID, 5 As System_Function_ID, 4 As Right_Type_ID, @storeid as Store_ID from [System_User] where System_User_ID not in ( /*Global system users that already have Manage User Base Menu Item*/ select su.System_User_ID from [System_User] su left outer join System_User_Function suf on suf.System_User_ID = su.System_User_ID where Locked = 0 and Global_User_ID is not null and System_Function_ID in (5) ) and Locked = 0 and Global_User_ID is not null /*Add Manage Profiles Menu Item*/ insert into System_User_Function (System_User_ID, System_Function_ID, Right_Type_ID, Store_ID) /*Users that do not already have Manage Profiles Menu Item*/ select System_User_ID, 6 As System_Function_ID, 4 As Right_Type_ID, @storeid as Store_ID from [System_User] where System_User_ID not in ( /*Global system users that already have Manage Profiles Menu Item*/ select su.System_User_ID from [System_User] su left outer join System_User_Function suf on suf.System_User_ID = su.System_User_ID where Locked = 0 and Global_User_ID is not null and System_Function_ID in (6) ) and Locked = 0 and Global_User_ID is not null end; Print 'Insert into script history if everything else is cool'; Insert into Script_History (RunDate,Script_Name) Values (CURRENT_TIMESTAMP,'SWIFT-2595'); IF @@ERROR != 0 BEGIN RAISERROR ('UNABLE TO CONTINUE WITH SCRIPT', 11, 1); RETURN; END GO