Create PROCEDURE [dbo].[C6_S_readPDF_ReportRestorati] -- 630143
@id as int
AS
BEGIN
declare @contIMG int
	SET NOCOUNT ON;
 SELECT  @contIMG=count(*)
  FROM [dbo].[C6ReportFisico] as C6ReportFisico
  WHERE Identificativo=@id
if @contIMG > 0
  SELECT C6ReportFisico.image
  FROM [dbo].[C6ReportFisico] as C6ReportFisico
  WHERE Identificativo=@id
else    
 select pdfimage 
  from  dbo.reportStorico 
  inner join dbo.RepositoryMetadati
on  identificativo=id
where idinrepository =@id
END