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
   |  
 
  -- si le trinôme code chaîne, code chantier et code établissement (ch_code, ct_code et et_code de TMP_CHANTIER) 
    -- existent dans la table COMPOSITION_CHAINE (via id_chaine, id_chantier_directuer, id_ca et id_ctc)
 
    select tcc.ch_code,
           tcc.ct_code,
           tcc.et_code,
           ch.id_chaine,
      	   ca.id_ca,
      	   cd.id_chantier_directeur,
      	   c.id_ctc
    from tmp_composition_chaine tcc, composition_chaine cc, chaine ch, chantier_annexe ca, chantier_directeur cd, ctc c, tmp_chantier tc
    where tc.ct_code = tcc.ct_code      
      and tcc.ch_code = ch.code_chaine and ch.id_chaine = cc.id_chaine 
      and cc.date_fin is null
      and ca.date_fin is null
      and cd.date_fin is null
      and ch.date_fin is null
      and c.date_suppression is null
      and tcc.ct_code = ca.code_ca(+) 
      and ((ca.id_ca is not null and ca.id_ca = cc.id_ca) or (ca.id_ca is null))     
      and tcc.ct_code = cd.code_cd(+) 
      and ((cc.id_chantier_directeur is not null and cd.id_chantier_directeur = cc.id_chantier_directeur) or (cd.id_chantier_directeur is null))
      and ( tcc.et_code = c.code_ctc and c.id_ctc = cc.id_ctc )  
 
    UNION 
    -- si le trinôme code chaîne, code chantier et code établissement (ch_code, ct_code et et_code de TMP_CHANTIER) 
    -- n'existent pas dans la table COMPOSITION_CHAINE (via id_chaine, id_chantier_directuer, id_ca et id_ctc)
    select tcc.ch_code,
           tcc.ct_code,
           tcc.et_code,
           ch.id_chaine,
      	   ca.id_ca,
      	   cd.id_chantier_directeur,
      	   c.id_ctc
    from tmp_composition_chaine tcc, tmp_chantier tc, ctc c, chantier_directeur cd, chantier_annexe ca, chaine ch
    where tcc.et_code = c.code_ctc
      and tc.ct_code = tcc.ct_code
      and c.date_suppression is null
      and ca.date_fin is null
      and cd.date_fin is null
      and ch.date_fin is null
      and tcc.ct_code = ca.code_ca(+) 
      and tcc.ct_code = cd.code_cd(+) 
      and tcc.ch_code = ch.code_chaine
          -- ch_code (TMP_COMPOSITION_CHAINE) est présent dans la table TMP_CHAINE
      and tcc.ch_code in (select ch_code from tmp_chaine tch where tch.ch_code = tcc.ch_code)
          -- ct_code (TMP_COMPOSITION_CHAINE) est présent dans la table TMP_CHANTIER
      and tcc.ct_code in (select ct_code from tmp_chantier tc where tc.ct_code = tcc.ct_code)
          -- si ct_type_local (TMP_CHANTIER) du ct_code de TMP_COMPOSITION_CHAINE est égale à 'D', co_fl_amont_aval 
          -- (TMP_COMPOSITION_CHAINE) est égale à 'D'
      and tc.ct_type_local = tcc.co_fl_amont_aval
      and tcc.co_no_ordre is not null 
      and tcc.co_coeff_bcl is not null | 
Partager