1 2 3 4 5 6 7 8 9 10 11 12 13
| SELECT res.ID_CONTRAT, res.ID_INDIVIDU, RES.ELT_ROLE, RES.DAT_CRE, RES.BOO_SIGNATAIRE, RES.BOO_CONDAMNE FROM
(
SELECT TTC.ID_CONTRAT , TTIC2.ID_INDIVIDU, TTIC2.ELT_ROLE, TTIC2.DAT_CRE, TTIC2.BOO_SIGNATAIRE, TTIC2.BOO_CONDAMNE
FROM #tmp_TG_CONTRAT TTC INNER JOIN
#tmp_TL_IND_CONTRAT_FULL TTIC1 on TTIC1.ID_CONTRAT = TTC.ID_CONTRAT INNER JOIN
#tmp_TG_CONTRAT TTC1 on TTC.ID_RC = TTC1.ID_RC INNER JOIN
#tmp_TL_IND_CONTRAT_FULL TTIC2 on TTC1.ID_CONTRAT = TTIC2.ID_CONTRAT
WHERE TTC.ID_RC = TTC1.ID_RC
AND NOT EXISTS (SELECT * FROM TL_IND_CONTRAT TICR WHERE (TICR.ID_INDIVIDU=TTIC2.ID_INDIVIDU AND TICR.ID_CONTRAT=TTC.ID_CONTRAT))
) res
group by res.ID_CONTRAT, res.ID_INDIVIDU
having COUNT(*) > 0
ORDER BY res.ID_CONTRAT |
Partager