﻿-- Stored procedure
--[sp_readPDFImage_New] 1,0
CREATE PROCEDURE [dbo].[sp_readPDFImage_New]
@id as int,
@pdfC6 as int
AS
BEGIN
	SET NOCOUNT ON;
	IF(@pdfC6 = 0)
		BEGIN
			SELECT [FILEREPORT],isnull(IndiceNavigatore,-1) IndiceNavigatore,isnull(IndiceCopertina,-1) IndiceCopertina,isnull(ReportDopoC6,0) ReportDopoC6
			FROM [dbo].[REPORTFISICO]
			WHERE IDENTIFICATIVO=@ID
		END
	ELSE IF (@pdfC6 = 2)
        BEGIN
			SELECT [IMAGE] AS FILEREPORT,-1 IndiceNavigatore,-1 IndiceCopertina,0 ReportDopoC6
			FROM [dbo].[C6REPORTFISICO_CAMPAGNA]
			WHERE IDENTIFICATIVO=@ID
		END
	ELSE IF (@pdfC6 = 1)
		BEGIN
			SELECT [IMAGE] AS FILEREPORT,-1 IndiceNavigatore,-1 IndiceCopertina,0 ReportDopoC6
			FROM [dbo].[C6REPORTFISICO]
			WHERE IDENTIFICATIVO=@ID
		END
	ELSE IF (@pdfC6 = 3)
		BEGIN
			SELECT [PDFIMAGE] AS FILEREPORT,-1 IndiceNavigatore,-1 IndiceCopertina,0 ReportDopoC6
			FROM [dbo].[ReportStorico]
			WHERE IDENTIFICATIVO=@ID
		END
	ELSE IF (@pdfC6 = 5)
		BEGIN
			SELECT [FILEREPORT] AS FILEREPORT,-1 IndiceNavigatore,-1 IndiceCopertina,0 ReportDopoC6
			FROM [dbo].[ReportFMS]
			WHERE IDENTIFICATIVO=@ID
		END
END