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
| DECLARE @EVENT_TYPE_SORTING Int = 2 -- Tri
DECLARE @EVENT_TYPE_REJECT Int = 34 -- Rejet
DECLARE @systemNum int ='0'
DECLARE @StartDateTime DateTime
DECLARE @EndDateTime DateTime
SELECT DISTINCT
D.Sortingtype as type,
p.Id as IdColis,
coalesce(IDT13.[Barcode],' ') as Cab_Suivi,
coalesce(IDT24.[Barcode],' ') as Cab_Pch,
coalesce(IDT28.[Barcode],' ') as Cab_Geolabel
FROM [Parcel] AS P with(nolock)
Left outer join [Barcode] as IDT24 with(nolock) on IDT24.[ParcelId] = P.[Id] and len(IDT24.[Barcode])='24'
Left outer join [Barcode] as IDT13 with(nolock) on IDT13.[ParcelId] = P.[Id] and len(IDT13.[Barcode])='13'
Left outer join [Barcode] as IDT28 with(nolock) on IDT28.[ParcelId] = P.[Id] and len(IDT28.[Barcode])='28'
Inner join [ParcelEvent] as PE with(nolock) on PE.[ParcelId] = P.[Id] and PE.EventTypeNum IN(@EVENT_TYPE_SORTING, @EVENT_TYPE_REJECT)
INNER join chute as C
on C.Num=P.PhysicalChuteNum
INNER join Vacation as V
ON V.Id=P.VacationId
INNER join tache as T
on T.Id=V.IdTache
INNER JOIN dsc as D
on D.chute=C.num and D.Idtache=T.id
WHERE P.SystemNum=@SystemNum and PE.[DateTime] BETWEEN @StartDateTime AND @EndDateTime
GROUP BY
D.Sortingtype,
p.Id,
coalesce(IDT13.[Barcode],' ') ,
coalesce(IDT24.[Barcode],' ') ,
coalesce(IDT28.[Barcode],' ')
OPTION (OPTIMIZE FOR (
@StartDateTime = '20191127 04:30:00'
, @EndDateTime = '20191128 04:30:00'
)
) |
Partager