Before running the script, do the following:
SELECT operand_name AS account_name, operand_id AS oid FROM t_av_change_request_details crds WHERE crds.operand_type = 'AC' AND crds.full_operation = 'CreateAccount' AND crds.state in ('RJ', 'CA') AND NOT exists (-- Exclude accounts that had not been completely rejected SELECT 1 FROM t_av_change_request_details cri WHERE ((cri.operand_type = 'AC' AND cri.operand_id = crds.operand_id) OR (cri.value_type = 'AC' AND cri.value_id = crds.operand_id)) AND cri.state NOT IN ('RJ', 'CA')) AND NOT exists (-- Exclude collected accounts SELECT 1 FROM t_av_accounts acc where acc.id = crds.operand_id AND acc.adc_id > 0) ;