DELETE FROM AC_MEMBERTIMESTAMP WHERE MEMBERID IN (SELECT MEMBERID FROM AC_MEMBERENROLLMENT WHERE MECO_STATUS = 'ERRONEOUS')
DELETE FROM AC_ACCESSVERIFICATIONCUSTOMER WHERE MEMBERID IN (SELECT MEMBERID FROM AC_MEMBERENROLLMENT WHERE MECO_STATUS = 'ERRONEOUS')
DELETE FROM AC_MEMBERENROLLMENT WHERE MECO_STATUS = 'ERRONEOUS'
DELETE FROM AC_USERS WHERE AccessTemplateRights = FALSE
DELETE FROM AC_AccessVerificationCustomer WHERE (((AC_AccessVerificationCustomer.[AccessVerificationCustomerId]) In (select b.AccessVerificationCustomerId from (select Memberid, MAX(AccessVerificationCustomerId) as maxid from AC_AccessVerificationCustomer where ProductId = 0 ANd MemberProductInfoId = 0 group by Memberid, productType, ProductId, MemberProductInfoId having COUNT(*) > 1) a INNER JOIN AC_AccessVerificationCustomer b on a.MemberID = b.MemberID and a.maxid <> b.AccessVerificationCustomerId where  b.MemberProductInfoId = 0 and b.ProductId = 0)));
DELETE FROM Ac_MemberEnrollment where memberid in (Select MemberID from (select MemberID,MAX(ValidTo) as MaxExpiry from ac_accessverificationcustomer GROUP BY MemberID)obj where obj.MaxExpiry <= format(Now -180,'dd-MMM-yyyy'))
DELETE FROM ac_accessverificationcustomer where memberid in (Select MemberID from (select MemberID,MAX(ValidTo) as MaxExpiry from ac_accessverificationcustomer GROUP BY MemberID)obj where obj.MaxExpiry <= format(Now -180,'dd-MMM-yyyy'))