
-- Recherche police
SELECT  police.*  
FROM police
WHERE libellePolice LIKE '%ECORIGINE%'


-- date de debut
SELECT  '2022-01-01'  INTO @DateEffet

-- date de fin
SELECT  '2022-12-31'  INTO @DateFin


-- id police
SELECT  '218'  INTO @police


UPDATE police AS p 
INNER JOIN avenant  a ON (p.id=a.idPolice)
INNER JOIN contrat  c  ON (p.id=c.idPolice)
INNER JOIN entetecontrat  e  ON (p.id=e.idPolice)
INNER JOIN adherent  ad ON (p.id=ad.idPolice)
INNER JOIN beneficiaire  b ON ((p.id=b.idPolice) AND (ad.id=b.idAdherent))
INNER JOIN beneficiaireprime  bp ON ((p.id=bp.idPolice) AND (a.id=bp.idAvenant) AND (ad.id=bp.idAdherent) AND (b.id=bp.idBeneficiaire) )
SET 
p.dateEffet=@DateEffet-- ,p.dateAvenant=@DateEffet,
,p.dateEcheance=@DateFin ,p.dateFin=@DateFin ,p.dateEffetInitial=@DateEffet,p.dateCre=@DateEffet,
a.dateEffet=@DateEffet,a.dateCre=@DateEffet,
c.dateEffet=@DateEffet,c.dateFin=@DateFin,
e.dateEffet=@DateEffet,e.dateFin=@DateFin,
ad.dateEffet=@DateEffet,
b.dateEffet=@DateEffet,
bp.dateEffetPolice=@DateEffet,bp.dateFinPolice=@DateFin,bp.dateEffetAdherent=@DateEffet,bp.dateEffetBeneficiaire=@DateEffet,bp.dateEffet=@DateEffet
WHERE a.codeTypeAvenant='AFN' AND a.idPolice IN (@police)


UPDATE police SET dateAvenant='01/01/2022' WHERE id IN (218)