USE [TWO] GO /****** Object: StoredProcedure [dbo].[spcpAvataxPreSave] Script Date: 09/20/2012 07:13:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[spcpAvataxPreSave] @Sales_Doc_Type as varchar(25), @Sales_Doc_Num as varchar(50) AS if exists (SELECT * FROM SOP10100 as sd join spvSalesDocType as sdt on sd.SOPTYPE = sdt.SOPTYPE WHERE (sd.TAXSCHID='AVATAX' OR sd.TAXSCHID='SABRIX' OR sd.TAXSCHID like 'CCH%' OR sd.TAXSCHID like 'STO%' OR sd.TAXSCHID LIKE 'VERTEX%' or sd.TAXSCHID = 'WEBTAXES') AND sd.SOPNUMBE = @Sales_Doc_Num AND sdt.Sales_Doc_Type = @Sales_Doc_Type) BEGIN DELETE t from SOP10105 as t join SOP10100 as sd on t.SOPNUMBE = sd.SOPNUMBE and t.SOPTYPE = sd.SOPTYPE join spvSalesDocType as sdt on sd.SOPTYPE = sdt.SOPTYPE WHERE sd.SOPNUMBE = @Sales_Doc_Num AND sdt.Sales_Doc_Type = @Sales_Doc_Type DELETE t from SOP10102 as t join SOP10100 as sd on t.SOPNUMBE = sd.SOPNUMBE and t.SOPTYPE = sd.SOPTYPE join spvSalesDocType as sdt on sd.SOPTYPE = sdt.SOPTYPE WHERE sd.SOPNUMBE = @Sales_Doc_Num AND sdt.Sales_Doc_Type = @Sales_Doc_Type END