-- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE RemoveDuplicatesFromComplexConditions -- Add the parameters for the stored procedure here AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; IF ((SELECT count(name) FROM sys.tables WHERE name='holdkey')=1) DROP TABLE holdkey; IF ((SELECT count(name) FROM sys.tables WHERE name='holddups')=1) DROP TABLE holddups; SELECT condition1, condition2, col3=count(*) INTO holdkey FROM ComplexConditions GROUP BY condition1, condition2 HAVING count(*) > 1 SELECT DISTINCT ComplexConditions.* INTO holddups FROM ComplexConditions, holdkey WHERE ComplexConditions.condition1 = holdkey.condition1 AND ComplexConditions.condition2 = holdkey.condition2; --SELECT attribute1, attribute2, count(*) --FROM holddups --GROUP BY attribute1, attribute2; DELETE ComplexConditions FROM ComplexConditions, holdkey WHERE ComplexConditions.condition1 = holdkey.condition1 AND ComplexConditions.condition2 = holdkey.condition2; INSERT ComplexConditions SELECT distinct condition1, condition2, type FROM holddups; DELETE FROM ComplexConditions WHERE id IN (SELECT c2.id from ComplexConditions c1, ComplexConditions c2 where c1.condition1=c2.condition2 and c1.condition2=c2.condition1 and c1.id