SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
create procedure [dbo].[p_policies_update_clients_introducers]
	@policies_situations_table type_table_id readonly
as
	set nocount on;

	update ac
		set cli_introducer_id = ppsi.polsi_introducer_id
	from act_clients ac
		inner join pol_policies pp on pp.pol_client_id = ac.cli_actor_id
		inner join pol_policies_situations pps on pols_policy_id = pp.pol_policy_id
		inner join @policies_situations_table pst on pst.id = pps.pols_policy_situation_id
		inner join pol_policies_situations_introducers ppsi on ppsi.polsi_policy_situation_id = pps.pols_policy_situation_id
	where ac.cli_introducer_id is null
GO
