/***************************************
* STORED stp_AUD_ByUDC
*
* ottiene l'elenco degli UDC + AL + cont Dtx per un UDC
*
* Steamware, S.E.L.
* mod: 2014.03.19
*
****************************************/
create PROCEDURE [dbo].[stp_AUD_ByUDC]
(
	@UDC	VARCHAR(50) = ''
)
AS

SELECT a2u.AL
	, ec.UDC
	, ec.Particolare
	, ec.Qta
	, COUNT(d2u.DataMatrix) AS QtaDtx
FROM ElencoCartellini AS ec
INNER JOIN AL2UDC AS a2u
	ON a2u.UDC = ec.UDC
LEFT JOIN Dtx2UDC AS d2u
	ON ec.UDC = d2u.UDC
WHERE a2u.UDC = @UDC
GROUP BY a2u.AL
	, ec.UDC
	, ec.Particolare
	, ec.Qta
ORDER BY a2u.AL, ec.UDC

RETURN