/***************************************
* STORED stp_UdcDetailGetByAL
*
* ottiene l'elenco degli UDC con dettaglio per un dato AL
*
* Steamware, S.E.L.
* mod: 2014.03.12
*
****************************************/
create PROCEDURE [dbo].[stp_UdcDetailGetByAL]
(
	@AL NVARCHAR(50)
)
AS

SELECT ec.UDC
	, ec.RagSociale
	, ec.Particolare
	, ec.DescParticolare
	, ec.DisegnoGrezzo
	, ec.Esponente
	, ec.DescImpianto
	, ec.DataFus
	, ec.TurnoFus
	, ec.CodImballo
	, ec.Qta
	, sp.DescStato
	, ec.ModDate
	, ISNULL(b.CodMag, N'') AS CodMag
	, ISNULL(b.CodBlocco, N'') AS CodBlocco
	, ISNULL(c.CodCella, N'') AS CodCella
	, ISNULL(c.IdxCella, 0) AS IdxCella
	, ISNULL(c.X, 0) AS X
	, ISNULL(c.Y, 0) AS Y
	, ISNULL(c.Z, 0) AS Z
	, ec.IdxPosizione
	, ISNULL(ec.Note, N'') AS Note
	, puc.DataRif AS lastMov
FROM Celle AS c
INNER JOIN PosizioneUdcCorrente AS puc
	ON c.IdxCella = puc.IdxCella
		AND c.IdxCella = puc.IdxCella
		AND c.IdxCella = puc.IdxCella
INNER JOIN Blocchi AS b
	ON c.IdxBlocco = b.IdxBlocco
INNER JOIN ElencoCartellini AS ec
	ON puc.UDC = ec.UDC
LEFT JOIN AnagStatiProdotto AS sp
	ON ec.CodStato = sp.CodStato
		AND ec.CodStato = sp.CodStato
INNER JOIN AL2UDC AS a2u
	ON a2u.UDC = ec.UDC
WHERE (a2u.AL = @AL)

ORDER BY	puc.DataRif DESC

RETURN