declare @NoOrden varchar(18);
declare @TiendaId integer;
DECLARE @OrdenEntrega TABLE(ordenentregaid bigint, noorden varchar(18), tiendaremisionid bigint, tiendaentregaid bigint);
USE fleet_management;
— TIENDA ENTREGA
SET @TiendaId= 1318
— ORDEN DE ENTREGA
SET @NoOrden = 634659
BEGIN TRANSACTION;
INSERT INTO @OrdenEntrega (ordenentregaid, noorden, tiendaremisionid, tiendaentregaid)
SELECT DISTINCT oe.ordenentregaid, oe.noorden, oe.tiendaremisionid, oea.tiendaentregaid
FROM ordenentrega oe WITH(NOLOCK)
INNER JOIN OrdenEntregaArticulo oea WITH(NOLOCK) ON oea.ordenentregaid = oe.ordenentregaid AND oea.tiendaentregaid = @TiendaId
WHERE oe.noorden = @NoOrden –AND oe.ordenentregaid IN (18606267)
COMMIT TRANSACTION;
SELECT ts.horainicio, ts.horafin, ts.codigoid AS ‘TICKET SURTIDO’, oe.noorden AS ‘ORDEN’, oea.NoArticulo AS ‘SKU’, oea.nosecuencia AS ‘SECUENCIA’, oea.pedido AS ‘QTY VTA’, tsd.cantidadconfirmacion AS ‘QTY SURTIDA’, ts.surtidofleet AS ‘FLEET/TC70’, ts.lpn, ts.foliolpn, ts.ticketsurtidoid
FROM ticketSurtido ts WITH(NOLOCK)
INNER JOIN @OrdenEntrega o ON o.ordenentregaid = ts.OrdenEntregaID
INNER JOIN TicketSurtidoDetalle tsd WITH(NOLOCK) ON tsd.TicketSurtidoID = ts.ticketsurtidoid
INNER JOIN ordenentregaarticulo oea ON oea.ordenentregaid = ts.ordenentregaid AND oea.ordenentregaarticuloid = tsd.ordenentregaarticuloid
INNER JOIN ordenentrega oe ON oe.ordenentregaid = ts.ordenentregaid
–WHERE ts.lpn = ‘CGM000003203’
ORDER BY ts.horainicio, oea.nosecuencia
