GO
/****** Oggetto:  StoredProcedure [dbo].[getGestioneLineeProd]    Data script: 06/17/2010 16:17:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Valeria
-- Create date: 17/11/2009
-- Description:	ritorna le linee della PrintPDF con l'abilitazione ad inserire gli allegati
-- =============================================
ALTER PROCEDURE [dbo].[getGestioneLineeProd]
	-- Add the parameters for the stored procedure here
	@IDUtente int,
	@IDProduzione int,
	@CodStabilimento nvarchar(50),
	@Stabilimento nvarchar(50)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
IF @IDProduzione IS NULL  OR @IDProduzione = 0
	SELECT     PrintPDF.P099 AS Stabilimento ,PrintPDF.P006 AS Linea, ISNULL(gestioneLineeProd.stampaSchemi,0) AS stampaSchemi
	FROM      PrintPDF LEFT OUTER JOIN gestioneLineeProd ON PrintPDF.P006 = gestioneLineeProd.Linea AND PrintPDF.P099 = gestioneLineeProd.Stabilimento
	WHERE     (PrintPDF.IDUtente = @IDUtente) AND (PrintPDF.P099 = @CodStabilimento)  
	GROUP BY  PrintPDF.P099 ,PrintPDF.P006, gestioneLineeProd.stampaSchemi
    ORDER BY  PrintPDF.P099 ,PrintPDF.P006, gestioneLineeProd.stampaSchemi
ELSE
	SELECT     PrintPDF.P099 AS Stabilimento ,PrintPDF.P006 AS Linea, ISNULL(gestioneLineeProd.stampaSchemi,0) AS stampaSchemi
	FROM      PrintPDF LEFT OUTER JOIN gestioneLineeProd ON PrintPDF.P006 = gestioneLineeProd.Linea AND PrintPDF.P099 = gestioneLineeProd.Stabilimento
	WHERE     (PrintPDF.IDUtente = @IDUtente) AND (PrintPDF.P099 = @CodStabilimento) AND (PrintPDF.P002 = @IDProduzione)  
	GROUP BY   PrintPDF.P099 ,PrintPDF.P006, gestioneLineeProd.stampaSchemi
    ORDER BY  PrintPDF.P099 ,PrintPDF.P006, gestioneLineeProd.stampaSchemi
END