
/***************************************
* STORED stp_getUdcDetailFullCode
*
* ottiene l'elenco degli UDC con i dati significativi partendo da un valore da cercare come LIKE in 
*  - UDC
*  - Particolare
*
* Steamware, S.E.L.
* mod: 2010.05.24
*
****************************************/
CREATE PROCEDURE [dbo].[stp_getUdcDetailLikeSearch]
(
	@searchVal VARCHAR(50),
	@CodCS VARCHAR(2)	
)
AS

SELECT		ElencoCartellini.UDC, ISNULL(ElencoCartellini.RagSociale, N'') AS RagSociale, ISNULL(ElencoCartellini.Particolare, N'') AS Particolare,
			ISNULL(ElencoCartellini.DescParticolare, N'') AS DescParticolare, ISNULL(ElencoCartellini.DisegnoGrezzo, N'') AS DisegnoGrezzo, 
            ISNULL(ElencoCartellini.Esponente, N'') AS Esponente, ISNULL(ElencoCartellini.DescImpianto, N'') AS DescImpianto,
            ISNULL(ElencoCartellini.DataFus, N'') AS DataFus, ISNULL(ElencoCartellini.TurnoFus, 0) AS TurnoFus, ElencoCartellini.CodImballo, 
            ElencoCartellini.Qta,  ISNULL(AnagStatiProdotto.DescStato, N'') AS DescStato, ElencoCartellini.ModDate, 
            ISNULL(Blocchi.CodMag, N'') AS CodMag, ISNULL(Blocchi.CodBlocco, N'') AS CodBlocco, ISNULL(Celle.CodCella, N'') AS CodCella, 
			ISNULL(dbo.Celle.IdxCella, 0) AS IdxCella, ISNULL(Celle.X, 0) AS X, ISNULL(Celle.Y, 0) AS Y, ISNULL(Celle.Z, 0) AS Z, ElencoCartellini.IdxPosizione,
			ISNULL(ElencoCartellini.Note, '') AS Note,
			dbo.PosizioneUdcCorrente.DataRif AS lastMov
FROM		AnagStatiProdotto RIGHT OUTER JOIN ElencoCartellini
			ON AnagStatiProdotto.CodStato = ElencoCartellini.CodStato AND AnagStatiProdotto.CodStato = ElencoCartellini.CodStato 
			LEFT OUTER JOIN Celle INNER JOIN PosizioneUdcCorrente 
			ON Celle.IdxCella = PosizioneUdcCorrente.IdxCella AND Celle.IdxCella = PosizioneUdcCorrente.IdxCella AND 
            Celle.IdxCella = PosizioneUdcCorrente.IdxCella INNER JOIN
            Blocchi ON Celle.IdxBlocco = Blocchi.IdxBlocco INNER JOIN
            AnagMag ON Blocchi.CodMag = AnagMag.CodMag AND Blocchi.CodCS = AnagMag.CodCS AND Blocchi.CodMag = AnagMag.CodMag AND 
            Blocchi.CodCS = AnagMag.CodCS AND Blocchi.CodMag = AnagMag.CodMag AND Blocchi.CodCS = AnagMag.CodCS ON 
            ElencoCartellini.UDC = PosizioneUdcCorrente.UDC
WHERE       (ElencoCartellini.CodCS = @CodCS) AND 
			((ElencoCartellini.UDC like '%'+ @searchVal+'%') OR (ElencoCartellini.Particolare like '%'+ @searchVal+'%') OR 
			(ElencoCartellini.RagSociale like '%'+ @searchVal+'%'))

RETURN
