CREATE PROCEDURE [dbo].[sp_deleteDocumentFromDB_ByIdDocument]
@idDocument as int,
@idRepository as int
AS
BEGIN
	SET NOCOUNT ON;
BEGIN TRANSACTION
IF(@idRepository=0)
	BEGIN
	--figli
	 DELETE FROM [dbo].[ReportLog]
		  WHERE Identificativo = @idDocument;
	DELETE FROM [dbo].[ReportFisicoUltDati]
		  WHERE Identificativo = @idDocument;
	--padri
	DELETE FROM [dbo].[ReportFisico]
		  WHERE Identificativo = @idDocument;
	DELETE FROM [dbo].[ReportperClienteDati]
		  WHERE Identificativo = @idDocument;
	END
ELSE IF(@idRepository=5)
	BEGIN
		DELETE FROM [dbo].[ReportFMS]
		  WHERE Identificativo = @idDocument;
	END
--V cancella dai metadati
delete from repositoryMetaDati where idInRepository = @idDocument and repository = @idRepository
COMMIT
END