Exemple de code (point de départ: la ligne possédant une série de compteurs):
COALESCE((SELECT TOP 1 p2.at_firstname + ' ' + p2.at_lastname as techInstall
FROM cciag_cc_compteur
left outer join aten_prod_machine on aten_prod_machine.at_idmachine = cciag_cc_compteur.at_idmachinecompteur
left outer join ATEN_GENE_TREEL treelMachine on treelMachine.AT_NOONKEY='db:' + cast(aten_prod_machine.at_idmachine as varchar) +'@ATEN_PROD_MACHINE'
left outer join ATEN_GENE_TREEL treelEquipement on treelMachine.at_idtreelfather = treelEquipement.at_idtreel and treelEquipement.AT_NOONKEY like '%@ATEN_PROD_EQUIPEMENTH'
left outer join ATEN_GENE_TREEL treelInstallation on treelEquipement.at_idtreelfather = treelInstallation.at_idtreel and treelInstallation.AT_NOONKEY like '%@ATEN_PROD_INSTALLATIONH'
left outer join ATEN_PROD_INSTALLATIONH on treelInstallation.AT_NOONKEY='db:' + cast(ATEN_PROD_INSTALLATIONH.AT_IDINSTALLATIONH as varchar) +'@ATEN_PROD_INSTALLATIONH'
left outer join aten_prod_person p2 on ATEN_PROD_INSTALLATIONH.AT_IDFIRSTTECHNICAL=p2.at_idperson
where cciag_cc_ligne.cciag_idligne=cciag_cc_compteur.cciag_idligne and aten_prod_machine.AF_EXTENDCODE in
(
select AT_EXTENDCODE from ATEN_ADMIN_EXTENDL where at_idextendl in
(
select at_idextendl from ATEN_ADMIN_EXTENDFIELDDESCRIPTION
where AT_IDEXTENDFIELD in
(
select AT_IDEXTENDFIELD from aten_admin_extendfield where AT_FIELDCODE = 'TECHNICIEN'
)
and AT_IDEXTENDTABLE =
(
select AT_IDEXTENDTABLE from ATEN_ADMIN_EXTENDTABLE where AT_EXTENDTABLE = 'ATEN_PROD_MACHINE'
)
)
) order by techInstall desc
),'') AS tech2,
cette requete récupère le technicien du compteur gmao et si inexistant celui de l'installation
RépondreSupprimer