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
| with src
as ( select
convert(varchar(10),CONVERT(date,lcte.VarAlphaUtil4,103),103) as 'Date_Import',
ARTICLE.CodeFamille,
ARTICLE.MotDirecteur,
article.CodeArticle,
ARTICLE.Designation1,
ARTICLE.QteDansStock1 as 'QTE_SILOG',
LCTC.QteResProdstk,
ARTICLE1.Terme3Employe,
LCTE.VarAlphaUtil4,
LCTE.LancementSolde,
LCTE.DateDebutSaisie,
LCTE.HeureDebutSaisie,
LCTE.MinuteDebutSaisie,
FAMRUB.VarNumUtil,
lcte.CodeLancement,
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',
convert(varchar(10),CONVERT(date,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)),103),103) as 'Date_a',
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_appro',
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,(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0)))) as 'heure',
convert(varchar(10),CONVERT(datetime,((LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0))),103),103) as 'JourR',
convert(varchar(10),CONVERT(datetime,((LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1) - CONVERT(time, DATEADD(hour, FAMRUB.VarNumUtil, 0))),103),103) as 'JourR1',
datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) as [test jour],
datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) as [test heure],
LCTE.MinuteDebutSaisie as [test minute],
case
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') and ((datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) >='0' and LCTE.MinuteDebutSaisie <= '59') and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) <'7' and LCTE.MinuteDebutSaisie <= '59')) then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1)),103),103) + ' ' + 'navette de 19H00'
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi') and ((datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) >='7' and LCTE.MinuteDebutSaisie <= '59') and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) <'19' and LCTE.MinuteDebutSaisie <= '59')) then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0)))),103),103) + ' ' + 'navette de 07H00'
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) = 'Samedi' and ((datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) >='7' and LCTE.MinuteDebutSaisie <= '59') and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) <'16' and LCTE.MinuteDebutSaisie <= '59')) then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0)))),103),103) + ' ' + 'navette de 07H00'
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi') and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) >='19' and LCTE.MinuteDebutSaisie <= '59') then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0)))),103),103) + ' ' + 'navette de 19H00'
when datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) ='0' and datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) in ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1)),103),103) + ' ' + 'navette de 19H00'
when datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) ='0' and datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) = 'Dimanche' then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1)),103),103) + ' ' + 'navette de 16H00'
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) in ('Samedi','Dimanche') and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) >='16' and LCTE.MinuteDebutSaisie <= '59') then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0)))),103),103) + ' ' + 'navette de 16H00'
when datename(DW,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) = 'Dimanche' and (datepart(HH,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))))) <'16' and LCTE.MinuteDebutSaisie <= '59') then convert(varchar(10),CONVERT(date,DATEADD(HOUR,(-1*FAMRUB.VarNumUtil),(LCTE.DateDebutSaisie + CONVERT(time, DATEADD(hour, LCTE.HeureDebutSaisie, 0))-1)),103),103) + ' ' + 'navette de 16H00'
Else 'y a un Bug'
END as 'navette'
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.DateDebutSaisie,
src.HeureDebutSaisie,
src.MinuteDebutSaisie,
src.[test jour],
src.[test heure],
src.[test minute],
src.VarNumUtil,
src.MotDirecteur,
src.CodeArticle,
src.Designation1,
round(sum(src.Qté),0) as 'Qté',
src.QTE_SILOG as 'stock',
src.navette,
CONVERT(datetime,SUBSTRING(src.navette,1,10),103) as 'DATE'
FROM src
WHERE src.LancementSolde='N' AND src.CodeFamille = '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))
and src.Terme3Employe in ('6110','6120','6140','6150','6160','6170','6180')
group by src.CodeArticle,src.navette, src.MotDirecteur, src.Designation1,CONVERT(datetime,SUBSTRING(src.navette,1,10),103),src.QTE_SILOG,src.DateDebutSaisie,src.HeureDebutSaisie,src.MinuteDebutSaisie,src.[test jour],src.[test heure],src.[test minute],src.VarNumUtil
order BY CONVERT(datetime,SUBSTRING(src.navette,1,10),103)desc,src.MotDirecteur |
Partager