SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_acc_invoices_delete_by_table_id]
	@invoices type_table_id READONLY
as 
	/*
	DGE 27/03/2017
	Suppression des quittances
	*/

	-- ris_risks_situations_main_invoices
	delete	dst 
	from	ris_risks_situations_main_invoices dst
			inner join @invoices ai on dst.rismi_invoice_id = ai.id

	-- acc_invoices_risks_variables_introducers
	delete	dst
	from	acc_invoices_risks_variables_introducers dst
			inner join @invoices ai on dst.invrisvi_invoice_id = ai.id


	-- acc_invoices_risks_variables_commission_taxes_cies
	delete dst
	from	acc_invoices_risks_variables_commission_taxes_cies dst
		inner join @invoices ai on dst.invrisvctc_invoice_id = ai.id
	

	-- acc_invoices_risks_variables_commission_taxes
	delete	dst
	from	acc_invoices_risks_variables_commission_taxes dst
			inner join @invoices ai on dst.invrisvct_invoice_id = ai.id


	-- acc_invoices_risks_variables_taxes_cies
	delete	dst
	from	acc_invoices_risks_variables_taxes_cies dst
			inner join @invoices ai on dst.invrisvtc_invoice_id = ai.id


	-- acc_invoices_risks_variables_taxes
	delete	dst
	from	acc_invoices_risks_variables_taxes dst
			inner join @invoices ai on dst.invrisvt_invoice_id = ai.id

	-- acc_invoices_risks_variables_cies
	delete	dst
	from	acc_invoices_risks_variables_cies dst
			inner join @invoices ai on dst.invrisvc_invoice_id = ai.id


	-- acc_invoices_risks_variables
	delete	dst
	from	acc_invoices_risks_variables dst
			inner join @invoices ai on dst.invrisv_invoice_id = ai.id


	-- acc_invoices_risks_situations
	delete dst
	from	acc_invoices_risks_situations dst
			inner join @invoices ai on dst.invris_invoice_id = ai.id


	--pol_policies_situations_main_invoices
	delete	dst 
	from	pol_policies_situations_main_invoices dst 
			inner join @invoices ai on dst.polmi_invoice_id = ai.id


	-- acc_invoices_policies_variables_introducers
	delete	dst
	from	acc_invoices_policies_variables_introducers dst
			inner join @invoices ai on dst.invpolvi_invoice_id = ai.id


	-- acc_invoices_policies_variables_commission_taxes_cies
	delete	dst
	from	acc_invoices_policies_variables_commission_taxes_cies dst
			inner join @invoices ai on dst.invpolvctc_invoice_id = ai.id


	-- acc_invoices_policies_variables_commission_taxes
	delete dst
	from acc_invoices_policies_variables_commission_taxes dst
		inner join @invoices ai on dst.invpolvct_invoice_id = ai.id


	-- acc_invoices_policies_variables_taxes_cies
	delete	dst
	from	acc_invoices_policies_variables_taxes_cies dst
			inner join @invoices ai on dst.invpolvtc_invoice_id = ai.id


	-- acc_invoices_policies_variables_taxes
	delete	dst
	from	acc_invoices_policies_variables_taxes dst
			inner join @invoices ai on dst.invpolvt_invoice_id = ai.id


	-- acc_invoices_policies_variables_cies
	delete	dst 
	from	acc_invoices_policies_variables_cies dst
			inner join @invoices ai on dst.invpolvc_invoice_id = ai.id


	-- acc_invoices_policies_variables
	delete	dst
	from	acc_invoices_policies_variables dst
			inner join @invoices ai on dst.invpolv_invoice_id = ai.id
	

	-- acc_invoices_operations
	delete	dst
	from	acc_invoices_operations dst
			inner join @invoices ai on dst.invop_invoice_id = ai.id

	-- acc_invoices
	delete	dst
	from	acc_invoices dst
			inner join @invoices ai on dst.inv_invoice_id = ai.id

	-- acc_accounts
	delete	dst
	from	acc_accounts dst
			inner join @invoices ai on dst.a_account_id = ai.id


GO
