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
| INSERT INTO tag_ddd_delai
(numberprgn, ddd_delai_1, ddd_delai_2, sysmodtime)
SELECT tfa_ddd.numberprgn,
(CASE
WHEN tfa_ddd.sfr_ddd_date_fin IS NOT NULL
AND tfa_ddd.sfr_ddd_dt_a_quit_a_compl IS NOT NULL
THEN tfa_ddd.sfr_ddd_date_fin
- tfa_ddd.sfr_ddd_dt_a_quit_a_compl
- del1.sum_jr_non_ouv
END
) ddd_delai_1,
(CASE
WHEN tfa_ddd.sfr_ddd_date_fin IS NOT NULL
AND tfa_ddd.update_date IS NOT NULL
THEN tfa_ddd.sfr_ddd_date_fin
- tfa_ddd.update_date
- del2.sum_jr_non_ouv
END
) ddd_delai_2,
TRUNC (tmp_ddd.sysmodtime, 'MM')
FROM tfa_ddd, tmp_ddd
INNER JOIN
(SELECT COUNT (tdi_bitool_cal1.cpt_j_we) sum_jr_non_ouv
FROM tdi_bitool_cal tdi_bitool_cal1
WHERE tdi_bitool_cal1.cpt_j_fer = 1) del1
ON ( del1.date_d >= tfa_ddd.sfr_ddd_dt_a_quit_a_compl
AND del1.date_d <= tfa_ddd.sfr_ddd_date_fin
)
INNER JOIN
(SELECT COUNT (tdi_bitool_cal2.cpt_j_we) sum_jr_non_ouv
FROM tdi_bitool_cal tdi_bitool_cal2
WHERE tdi_bitool_cal2.cpt_j_fer = 1) del2
ON (del2.date_d BETWEEN tfa_ddd.update_date AND tfa_ddd.sfr_ddd_date_fin
)
WHERE tfa_ddd.sfr_ddd_a_quit_a_compl = 1
AND tmp_ddd.numberprgn = tfa_ddd.numberprgn; |
Partager