
declare @RoleActions table(
	[RoleId] [int] NOT NULL,
	actionid [int] NOT NULL,
	[Scope] [nvarchar](500) NULL
)

/*,Warehouse technician',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='F1C4B065-85CF-46C3-B262-E4FE26D9BA58' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'154260C0-7EAE-4CA6-8D37-0BD9B687419D',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'96639387-41E7-4D17-97D8-F5B71277201B',
'76086A65-F1F4-4E09-A5BC-F0C915B2A608',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')

/*,Technician',*/ insert into @RoleActions (roleid,ActionId,scope) select r.id,g.id,null from roles r , RoleActionTypes g where r.guid='A508E668-94BC-4076-A8EE-972ADAD06E64' and g.guid in (
'12BB55A5-EE3D-4759-8147-93C1F6130367',
'214A539A-2C0E-4761-8551-866D95DDC85A',
'8A5D98C8-9494-4701-A4B0-7B25E36B0E19',
'C77E1B9C-C59C-4003-AC35-31C1E3E4FED2',
'87EC56A0-AAB1-41B5-AB64-3C6A6D5D89E7',
'81F0E2D1-C469-4A55-AF24-1A4BB61C5B6F',
'BBA77A57-7B06-4503-8838-A48692A4EF4D',
'19D4B799-274B-449C-9172-570663382D68',
'7345D7FE-850B-4002-B960-202131CD7ECE',
'51051E8D-64E9-43DE-8A8B-E94D21F26943',
'7941180F-A491-4A04-8589-55E565BC317E',
'27850967-76A7-455B-AF03-7FE02D1580F8',
'E956D023-A3AB-47A2-B3BC-6BFF99337B10',
'86EAECDA-918A-48EC-B3EC-49D3FEB3F492',
'1EBA1260-C867-47C0-90AD-E1F1372E4878',
'47D32A00-EE97-44C5-957F-45654C8A27CD',
'B525BA9B-7A94-4B69-B03C-A6D61BFE133A')



MERGE INTO [dbo].RoleActions AS TARGET
USING @RoleActions AS SOURCE
	ON TARGET.roleid = SOURCE.roleid
	and TARGET.ActionId= SOURCE.ActionId
	WHEN MATCHED THEN    
			UPDATE SET scope=source.scope
	WHEN NOT MATCHED BY TARGET THEN   
			INSERT ( roleid,ActionId,scope) VALUES (Source.roleid,Source.ActionId,Source.scope)  
OUTPUT $action, SOURCE.*;
