﻿CREATE PROCEDURE [dbo].[SP_PDF_GETLOG]  --  [dbo].SP_PDF_GETLOG 3
	@idPdf BIGINT	
AS
BEGIN
	SET NOCOUNT ON; 
	 SELECT 
			 l.idPdf	
			,l.dtstamp	
			,l.idLogEvent	
			,l.idProvenienza				
			,e.Descrizione as EventDesc
			,e.FormatEvento				 
			,p.Descrizione as ProvDesc
		    ,CASE  WHEN e.FormatEvento = 2 THEN e.Descrizione + ' da ' + p.Descrizione  
				   WHEN e.FormatEvento = 1 THEN e.Descrizione 
			 ELSE '' END as Evento
			,(Select CodicePb FROM DocumentiPdf  WHERE idPdf = @idPdf) as utente
		FROM LogPdf  l
			  inner join LogEventPdf  e
			  on l.idLogEvent = e.idLogEvent 
			  inner join ProvenienzaPdf p
			  on l.idProvenienza = p.idProvenienza
			   WHERE idPdf = @idPdf
			   ORDER BY dtstamp
END