Advertisement
Jaumzera

Untitled

Apr 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. do $$
  2. declare
  3.     r_audit record;
  4.     r_pack record;
  5.     v_company_to_keep integer;
  6.  
  7. begin
  8.  
  9.     select id into v_company_to_keep from company where trading_name ilike 'ROCHE';
  10.     for r_audit in select id from audit where company_id <> v_company_to_keep
  11.     loop
  12.         raise notice 'Audit id %', r_audit.id;
  13.        
  14.         delete from bill_item_audit where audit_id = r_audit.id;
  15.         delete from audit_contract_service where audit_id = r_audit.id;
  16.         --delete from audit_marketing_discount where audit_id = r_audit.id;
  17.    
  18.         for r_pack in select * from audit_package where audit_id = r_audit.id
  19.         loop
  20.             raise notice 'Package id %', r_audit.id;
  21.             delete from audit_package_item where audit_package_id = r_pack.id;
  22.         end loop;
  23.    
  24.         delete from audit_package where audit_id = r_audit.id;
  25.         delete from audit where id = r_audit.id;
  26.  
  27.     end loop;
  28. end $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement