﻿CREATE PROCEDURE [dbo].[sp_deleteTemplateReportScheda]
@idTemplate as int
AS
BEGIN
	SET NOCOUNT ON;
BEGIN TRANSACTION
    declare @codicePB as  varchar(6)
    select   @codicePB=dbo.R6_ReportSchede_Template.codicePB FROM dbo.R6_ReportSchede_Template   --figli
		  WHERE R6_ReportSchede_Template.idTemplate = @idTemplate
   if @codicePB <> '' 
   BEGIN  
		DELETE FROM R6_ReportSchede_SchedeTemplate   --figli
			 WHERE R6_ReportSchede_SchedeTemplate.idTemplate = @idTemplate
		DELETE FROM dbo.R6_ReportSchede_Template   --figli
				WHERE R6_ReportSchede_Template.idTemplate = @idTemplate
	END  
COMMIT
END