/***************************************
* STORED stp_prtCartAnimeByUDC
*
* ottiene il record del Cartellino ANIME dato l'UDC richiesto x la stampa
*
* Steamware, G.A.R.
* mod: 2012.02.27
*
****************************************/
CREATE PROCEDURE [dbo].[stp_prtCartAnimeByUDC]
(
    @UDC NVARCHAR(50)
)
AS

    -- estraggo i trattamenti nelle note ( x max 10 trattamenti )
    -- NON SERVE PER I CARTELLINI ANIME MA TENGO DATASET IDENTICO
    DECLARE @tmp		NVARCHAR(500)
    DECLARE @NoteTratt	NVARCHAR(500)
    SET @NoteTratt = ''

    -- SET @NoteTratt = (SELECT SUBSTRING(@tmp, 0, LEN(@tmp)))

    -- ora seleziono i dati veri e propri
    SELECT
           e.UDC,
           e.CodCS,
           ISNULL( e.CodCliente,N'') AS      CodCliente,
           ISNULL( e.RagSociale,N'') AS      RagSociale,
           ISNULL( e.Particolare,N'') AS     Particolare,
           ISNULL( e.DescParticolare,N'') AS DescParticolare,
           ISNULL( e.DisegnoGrezzo,N'') AS   DisegnoGrezzo,
           ISNULL( e.Esponente,N'') AS       Esponente,
           ISNULL( e.CodImpianto,N'') AS     CodImpianto,
           ISNULL( e.DescImpianto,N'') AS    DescImpianto,
           ISNULL( e.CodStampo,N'') AS       CodStampo,
           ISNULL( e.Figura,N'') AS          Figura,
           e.DataFus,
           ISNULL( e.TurnoFus,0) AS        TurnoFus,
           ISNULL( e.CodImballo,N'') AS      CodImballo,
           ISNULL( e.CodSoggetto,N'') AS     CodSoggetto,
           ISNULL( e.NumCont,0) AS         NumCont,
           ISNULL( e.Tara,0) AS            Tara,
           ISNULL( e.Qta,0) AS             Qta,
           ISNULL( e.CodStato,N'') AS        CodStato,
           ISNULL( e.IdxPosizione,0) AS    IdxPosizione,
           ISNULL( e.PesoTot,0) AS         PesoTot,
           ISNULL( e.PesoCad,0) AS         PesoCad,
           e.CreateDate,
           e.ModDate,
           ISNULL( Op.Cognome,N'') AS     Cognome,
           ISNULL( Op.Nome,N'') AS        Nome,
           ISNULL( AnagStatiProdotto.DescStato,N'') AS      DescStato,
           ISNULL( RilPro.AnagImballi.DescImballo,N'') AS   DescImballo,
           RilPro.AnagParticolari.CodFamiglia,
           RilPro.AnagFamiglie.DescFamiglia,
           ISNULL( e.Note,N'') AS            Note,
           @NoteTratt AS                                    Notetratt
    FROM RilPro.AnagParticolari
    LEFT OUTER JOIN RilPro.AnagFamiglie
         ON RilPro.AnagParticolari.CodFamiglia = RilPro.AnagFamiglie.CodFamiglia
    RIGHT OUTER JOIN ElencoCartellini AS e
         ON RilPro.AnagParticolari.Particolare = e.Particolare
    LEFT OUTER JOIN AnagStatiProdotto
         ON e.CodStato = AnagStatiProdotto.CodStato
    LEFT OUTER JOIN RilPro.AnagOperatori Op
         ON e.CodSoggetto = Op.CodSoggetto
    LEFT OUTER JOIN RilPro.AnagImballi
         ON e.CodImballo = RilPro.AnagImballi.CodImballo
    WHERE e.UDC = @UDC;
 

RETURN
