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
| with src
as ( select
convert(varchar(10),CONVERT(date,lcte.VarAlphaUtil4,103),103) as 'Date_Import',
LCTC.CodeLancement,
ARTICLE1.Terme3Employe,
ARTICLE.CodeFamille,
ARTICLE.MotDirecteur,
ARTICLE.Designation1,
LCTC.QteResProdstk,
LCTE.VarAlphaUtil4,
LCTE.LancementSolde,
LCTE.DateDebutSaisie,
LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0)) as 'Date_de_Fab_planifiée',
(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)) as 'Date_appro',
FAMRUB.VarNumUtil as 'délai_retard',
(lcte.QuantiteLancee-lcte.QteFabEntreStk)*lctc.QteUnitaireTotale as 'Qté',
datename(DW,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0))) as 'Jour',
datename(DW,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0))) as 'Jour1',
datepart(hh,CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) as 'heure',
(datepart(DW,(convert(date,((LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)))))) + ' ' + datename(DW,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)))) as 'JourC',
datepart(D,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0))) as 'Jour1C',
convert(date,((LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)))) as 'Jour11',
datepart(DW,(convert(date,((LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)))))) as 'jourT'
FROM ARTICLE
inner join LCTC on LCTC.CodeRubrique=ARTICLE.CodeArticle
inner join LCTE on LCTE.CodeLancement=LCTC.CodeLancement
inner join Article as ARTICLE1 on ARTICLE1.codearticle=LCTE.codearticle
inner join FAMRUB on FAMRUB.CodeFamille=ARTICLE.CodeFamille
)
SELECT
SRC.Date_Import,
src.CodeLancement,
src.Terme3Employe,
src.CodeFamille,
src.MotDirecteur,
src.Designation1,
src.QteResProdstk,
src.Date_de_Fab_planifiée,
src.Date_appro,
src.Qté,
--"src.jourT,
--"src.Jour1C,
--"src.Jour11,
--"src.heure,
case
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and (src.heure >'0' and src.heure <='2') then src.Jour + ' ' + 'navette de 00H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and (src.heure >'2' and src.heure <='4') then src.jour + ' ' + 'navette de 02H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and (src.heure >'4' and src.heure <='10') then src.jour + ' ' + 'navette de 04H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and (src.heure >'10' and src.heure <='12') then src.jour + ' ' + 'navette de 10H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche') and (src.heure >'12' and src.heure <='14') then src.jour + ' ' + 'navette de 12H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi') and (src.heure >'14' and src.heure <='16') then src.jour + ' ' + 'navette de 14H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi') and (src.heure >'16' and src.heure <='22') then src.jour + ' ' + 'navette de 16H00'
when src.Jour in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and src.heure >'22' then src.jour + ' ' + 'navette de 22H00'
when src.heure ='0' then src.Jour1 + ' ' + 'navette de 22H00'
when src.Jour in ('Samedi') and (src.heure >'14' and src.heure <='18') then src.jour + ' ' + 'navette de 14H00'
when src.Jour in ('Samedi') and (src.heure >'18' and src.heure <='22') then src.jour + ' ' + 'navette de 18H00'
when src.Jour in ('Dimanche') and (src.heure >'0' and src.heure <='12') then src.jour1 + ' ' + 'navette de 22H00'
when src.Jour in ('Dimanche') and (src.heure >'14' and src.heure <='16') then src.jour + ' ' + 'navette de 14H00'
when src.Jour in ('Dimanche') and (src.heure >'16' and src.heure <='22') then src.jour + ' ' + 'navette de 16H00'
when src.Jour in ('Dimanche') and src.heure >'22' then src.jour + ' ' + 'navette de 22H00'
Else 'y a un Bug'
END
FROM src
WHERE src.LancementSolde='N' AND src.CodeFamille in ('cluster','POUDRES','POCHONS','EMB') and src.DateDebutSaisie is not null and src.VarAlphaUtil4<>''
and (convert(varchar(10),CONVERT(date,src.VarAlphaUtil4,103),103)=convert(varchar(10),CONVERT(date,GETDATE(),103),103) or convert(varchar(10),CONVERT(date,src.VarAlphaUtil4,103),103)=convert(varchar(10),CONVERT(date,GETDATE()-1,103),103))
ORDER BY src.Date_appro |
Partager