Hi All,
I am trying to automate this in a SSIS package. I can populate the user_groups table with the new groups for the new company. I just need to assign the menu access for new groups in the new company the same as company 1.
user_groups table is many rows. It has a row for each group in each company. The same group e.g 'approver' or 'sysadmin' has a different group ID for each company.
user_group_rights_new has many rows. It controls what menus each group id has. Hence each group_id is repeated with different menu item id.
I am trying to do a conditional insert. A new company is created e.g.'25' the company has new groups added , 'approver', 'sysadmin'. But they don't have any menu access. So that group_id doesn't exist in the user_group_rights_new. Now insert that group_id to with the same menu_items from the matching group 'approver', 'sysadmin' for company 1. Because the menu access doesn't change from company to company only the group_id number for that new group.
Current:
e.g.company_id 4 approver, admin, manager don't have any menu access yet.
Table User_groups
group_id-----Name----company_id
-21---approver------1
-5----admin---------1
-18---manager------1
-23---approver------2
-2----admin---------2
-130--approver-----4
-194--admin--------4
-18---manager-----4
Table user_group_rights_new
groupid------menu_item_id
-21-----------27
-21-----------26
-21-----------25
-21-----------24
-2-----------27
-2-----------26
-2-----------25
-2-----------24
Expected:
Table user_group_rights_new
groupid------menu_item_id
-21-----------27
-21-----------26
-21-----------25
-21-----------24
-21-----------27
-2-----------26
-2-----------25
-2-----------24
-130--------27
-130--------26
-130-------25
-130-------24
Now the approver group for company 4 group 130 'approver' has the same menu access the as the existing 'approver' group from company 1.
But when I run execute the stored proc i get an error message.
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I am trying to automate this in a SSIS package. I can populate the user_groups table with the new groups for the new company. I just need to assign the menu access for new groups in the new company the same as company 1.
user_groups table is many rows. It has a row for each group in each company. The same group e.g 'approver' or 'sysadmin' has a different group ID for each company.
user_group_rights_new has many rows. It controls what menus each group id has. Hence each group_id is repeated with different menu item id.
I am trying to do a conditional insert. A new company is created e.g.'25' the company has new groups added , 'approver', 'sysadmin'. But they don't have any menu access. So that group_id doesn't exist in the user_group_rights_new. Now insert that group_id to with the same menu_items from the matching group 'approver', 'sysadmin' for company 1. Because the menu access doesn't change from company to company only the group_id number for that new group.
Current:
e.g.company_id 4 approver, admin, manager don't have any menu access yet.
Table User_groups
group_id-----Name----company_id
-21---approver------1
-5----admin---------1
-18---manager------1
-23---approver------2
-2----admin---------2
-130--approver-----4
-194--admin--------4
-18---manager-----4
Table user_group_rights_new
groupid------menu_item_id
-21-----------27
-21-----------26
-21-----------25
-21-----------24
-2-----------27
-2-----------26
-2-----------25
-2-----------24
Expected:
Table user_group_rights_new
groupid------menu_item_id
-21-----------27
-21-----------26
-21-----------25
-21-----------24
-21-----------27
-2-----------26
-2-----------25
-2-----------24
-130--------27
-130--------26
-130-------25
-130-------24
Now the approver group for company 4 group 130 'approver' has the same menu access the as the existing 'approver' group from company 1.
SQL:
Create Procedure Buyer_User_Groups_Menu_Access_sp
@group_id INT = null,
@group_id2 INT = null,
@menu varchar(50) = null
AS
SET @group_id = (select id from user_groups)
SET @group_id2 = (select id from user_groups where user_groups.company_id = '1')
SET @menu = (select menu_item_id from user_group_rights_new where Group_id = @group_id2)
IF NOT Exists (select group_id from user_group_rights_new where Group_id = @group_id)
BEGIN
INSERT INTO user_group_rights_new
(Group_id,Menu_item_id)
SELECT
group_id = @group_id,
menu_item_id = @menu
END
But when I run execute the stored proc i get an error message.
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.