1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
SELECT t.contact_category,
t.contact_type,
t.name,
t.contact_id,
t.company_id as SIRET,
t.importance,
t.status,
t.client,
coalesce(j0.address_type,' ') AS address_type,
coalesce(j0.address,' ') AS address,
coalesce(j0.place,' ') AS place,
coalesce(j0.zip_code,' ') AS zip_code,
coalesce(j0.telephone_1,' ') AS telephone,
coalesce(j0.telephone_2,' ') AS fax,
coalesce(j0.telephone_3,' ') AS telex,
coalesce(j0.telephone_4,' ') AS mobile,
coalesce(j0.e_mail,' ') AS e_mail,
coalesce(j0.url_path,' ') AS url_path,
h.year_no AS annee,
sum(coalesce(d.cont_amount, 0)) AS versement_Brut_AnneeC , --montant brut
--sum(coalesce(d.NET_AMOUNT, 0)) AS versement_Net_AnneeC, -- montant net
--count(d.cont_amount) As nombre_versement
cl.cont_amount1,
cl.cont_amount2
FROM
ae6contact t
--Type de groupe
inner join ae6contactgroup g
ON t.contact_group = g.contact_group
AND g.sys_value = 'LEGAL'
AND g.client=t.client
AND g.status='N'
--Adresse
left outer join agladdress j0
ON j0.attribute_id='JC02'
AND t.client=j0.client
AND t.contact_id=j0.dim_value
AND j0.address_type='1'
--Promesse
INNER JOIN ae6aptxhead h
ON h.client = t.client
AND h.company_id = t.contact_id
AND h.STATUS = 'N' -- vu que vous êtes en jointure forte, ceci peut aller dans le where
--Detail Taxe
INNER JOIN ae6aptxdet d
ON d.client = h.client
AND d.apptaxhead_no = h.apptaxhead_no
AND d.STATUS = 'N' -- idem
--Collecteur
--inner join ae6aptxremit r
--- ON r.client = d.client
-- AND r.aptxremit_no = d.aptxremit_no
-- AND d.aptxremit_no > 0
INNER JOIN AVI_TAXE_VERSEMENT_COLONNE cl
ON cl.apptaxhead_no = h.apptaxhead_no
WHERE
t.client = 'P1'
AND t.STATUS = 'N'
AND t.contact_type = 'ENTREPRISE'
AND t.contact_category = 'ENTREPRISE'
AND h.year_no='2009'
Group by t.contact_category,t.contact_type,t.name,t.contact_id,t.company_id,t.importance,t.status,t.client,j0.address_type,
j0.address,j0.place,j0.zip_code,j0.telephone_1,j0.telephone_2,j0.telephone_3,j0.telephone_4,j0.e_mail,j0.url_path,h.year_no,
cl.cont_amount1,cl.cont_amount2
ORDER BY
t.name ASC,
h.year_no ASC |
Partager