SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE view [dbo].[vw_claim_main_actors]
as
	/*
	DGE 12/07/2017
	Déterminer le tiers principal d'un sinistre
	*/


	select	ca.clact_claim_id, clact_actor_id = min(ca.clact_actor_id)
	from	claim_actors ca
			inner join	(
						select	x.clact_claim_id, o = min(x.clact_order2)
						from	claim_actors x
						group by clact_claim_id
						) as t	on	t.clact_claim_id = ca.clact_claim_id
								and	t.o = ca.clact_order2
	group by ca.clact_claim_id


GO
