-- ==================================================================================
-- Author:		<Ernesto Serfilippi>
-- Create date: <27.02.2019>
-- Description:	<Aggiornamento Date Report di Immobiliare_GestionePDF>
-- ==================================================================================
CREATE PROCEDURE [C6MartPeriodicoImmobiliare].[UpdateDateReport_Immobiliare_GestionePDF]
	@IdReport int ,
  @DataReport datetime,
  @DataReportUpdate datetime,
  @DataZip datetime,
  @DataZipUpdate datetime,
  @DataInvio datetime,
  @DataInvioUpdate datetime,
  @NomeFile varchar(50), 
  @IdZip int ,
  @Return int OUTPUT
WITH EXEC AS CALLER
AS
/*
SP Body Comment
*/
	BEGIN TRANSACTION
    BEGIN TRY		
      IF @IDZip > 0
        BEGIN
    		UPDATE [C6MartPeriodicoImmobiliare].[Immobiliare_GestionePDF]      
    		SET
     				[DataReport] = @DataReport,
      			[DataReportUpdate] = @DataReportUpdate,
     				[DataZip] = @DataZip,
      			[DataZipUpdate] = @DataZipUpdate,
     				[DataInvio] = @DataInvio,
      			[DataInvioUpdate] = @DataInvioUpdate,
            [NomeFile] = @NomeFile,
            [IDZip] = @IdZip
      	WHERE [C6MartPeriodicoImmobiliare].[Immobiliare_GestionePDF].[IDReport] = @IdReport
    	  Set @Return=1;
        END
      ELSE
        BEGIN
    		UPDATE [C6MartPeriodicoImmobiliare].[Immobiliare_GestionePDF]      
    		SET
     				[DataReport] = @DataReport,
      			[DataReportUpdate] = @DataReportUpdate,
     				[DataZip] = @DataZip,
      			[DataZipUpdate] = @DataZipUpdate,
     				[DataInvio] = @DataInvio,
      			[DataInvioUpdate] = @DataInvioUpdate,
            [NomeFile] = @NomeFile
      	WHERE [C6MartPeriodicoImmobiliare].[Immobiliare_GestionePDF].[IDReport] = @IdReport
    	  Set @Return=1;
        END
    END TRY
	BEGIN CATCH
      IF ERROR_NUMBER()=2601 
      BEGIN
        IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION;
        Set @Return=-2601;
      END
     END CATCH
    IF @@TRANCOUNT > 0
      COMMIT TRANSACTION;