
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_tt_clients]
	@clients_table type_table_id readonly
as
	select	a.*, t.*, pr.*, cpl.*, 
			cli_branch_internal_reference = aab.act_internal_reference
	from vw_tt_act_clients a
		inner join @clients_table t on cli__act_actor_id = t.id
		inner join vw_tt_act_clients_pr pr on pr.clipr__act_actor_id = cli__act_actor_id
		left join act_cpl cpl on cpl.acpl_actor_id = cli__act_actor_id

		inner join act_clients cli on cli.cli_actor_id = a.cli__act_actor_id
		inner join act_actors aab on aab.act_actor_id = cli.cli_branch_id
GO
