
/***************************************
* STORED stp_UDC_FifoByParticolareBlocco
*
* restituisce elenco UDC a magazzino in logica FIFO per un dato particolare+blocco
*
* Steamware, S.E.L.
* mod: 2012.10.01
*
****************************************/
CREATE PROCEDURE stp_UDC_FifoByParticolareBlocco
(
	@CodCS			VARCHAR(2),
	@Particolare	VARCHAR(20),
	@idxBlocco		INT
)
AS

	SELECT	ec.UDC, c.CodCella, ec.DataFus, ec.Qta
	FROM	AnagMag am 
	INNER JOIN Blocchi b ON am.CodMag = b.CodMag AND am.CodCS = b.CodCS 
	INNER JOIN Celle c 
	INNER JOIN ElencoCartellini ec 
	LEFT OUTER JOIN PosizioneUdcCorrente puc ON ec.UDC = puc.UDC ON c.IdxCella = puc.IdxCella ON b.IdxBlocco = c.IdxBlocco 
	INNER JOIN AnagStatiProdotto asp ON ec.CodStato = asp.CodStato
	WHERE	(c.Attiva = 1) 
	        AND b.CodMag <> 'VMLP' 
	        AND (am.CodCS = @CodCS) 
	        AND (ec.Particolare = @Particolare) 
	        AND b.IdxBlocco = @idxBlocco
	GROUP BY	ec.UDC, c.CodCella, ec.DataFus, ec.Qta
	ORDER BY	ec.DataFus ASC
		
RETURN
