lundi 8 juin 2015

SELECT Entities.EntityId,
Entities.EntityName,
Entities.LegalName
FROM Entities
WHERE (Entities.EntityId IN
(SELECT Agreements.PrincipalId
FROM Agreements
WHERE ( ( (Agreements.BusinessLine IN (1, 2, 3)
AND Agreements.PrincipalManagingLocationId IN (144, 15, 16))
AND Agreements.AgreementGroupId IS NULL)
AND Agreements.BusinessLine NOT IN (4))
)
OR Entities.EntityId IN
(SELECT Agreements.CounterpartyId
FROM Agreements
WHERE ( ( (Agreements.BusinessLine IN (1, 2, 3)
AND Agreements.PrincipalManagingLocationId IN (144, 15, 16))
AND Agreements.AgreementGroupId IS NULL)
AND Agreements.BusinessLine NOT IN (4)) )) ;

SELECT
Entities.EntityId,
Entities.EntityName,
Entities.LegalName
FROM Entities
WHERE (Entities.EntityId IN
(SELECT Agreements.PrincipalId
FROM Agreements
WHERE ( ( (Agreements.BusinessLine IN (1, 2, 3)
AND Agreements.PrincipalManagingLocationId IN (144, 15, 16))
AND Agreements.AgreementGroupId IS NULL)
AND Agreements.BusinessLine NOT IN (4))
))
UNION all
SELECT
Entities.EntityId,
Entities.EntityName,
Entities.LegalName
FROM Entities
WHERE (Entities.EntityId NOT IN
(SELECT Agreements.PrincipalId
FROM Agreements
WHERE ( ( (Agreements.BusinessLine IN (1, 2, 3)
AND Agreements.PrincipalManagingLocationId IN (144, 15, 16))
AND Agreements.AgreementGroupId IS NULL)
AND Agreements.BusinessLine NOT IN (4))
))
AND (Entities.EntityId IN
(SELECT Agreements.CounterpartyId
FROM Agreements
WHERE ( ( (Agreements.BusinessLine IN (1, 2, 3)
AND Agreements.PrincipalManagingLocationId IN (144, 15, 16))
AND Agreements.AgreementGroupId IS NULL)
AND Agreements.BusinessLine NOT IN (4))
)) ;