title: Find the difference in table1 number of rows between sources S1 and S2 and update table2
body: <p><strong>TABLE1</strong></p>
  
  <pre><code>call_ID PARAM_CT status
  ------- -------- -------------    
  C001     3         NULL
  </code></pre>
  
  <p><strong>TABLE2</strong></p>
  
  <pre><code>+---------+---------+----------+----------+------------------+---------+    
  | seq_ID  | REQ_ID  | CALL_ID  | SELL_ID  |     REGION       |  NUMBER|    
  +---------+---------+----------+----------+------------------+---------+    
  |    1    |    123  | C001     | S1       | ABC              |  510563 |    
  |    2    |    123  | C001     | S1       | EFG              |  122967 |    
  |    3    |    123  | C001     | S1       | HIJ              |  614106 |    
  |    4    |    123  | C001     | S2       | ABC              |  510563 |    
  |    5    |    123  | C001     | S2       | ERG              |  122967 |    
  |    6    |    123  | C001     | S2       | HIJ              |  614106 |
  +---------+---------+----------+----------+------------------+---------+
  </code></pre>
  
  <p>Below is the code that i am using to find the difference in number of rows between sources S1 and S2. Please let me know if this can be optimized.</p>
  
  <pre><code>DECLARE vPARAM_CT VARCHAR(10) ;
  DECLARE vSOURCE1 VARCHAR(10) ;
  DECLARE vSOURCE2 VARCHAR(10) ;
  BEGIN
  SELECT PARAM_CT into vPARAM_CT FROM table1 WHERE call_id='C001' ;
  SELECT COUNT(*) INTO vSOURCE1 FROM table2 WHERE call_id='C001' AND SOURCE='S1';
  SELECT COUNT(*) INTO vSOURCE2 FROM table2 WHERE call_id='C001' AND SOURCE='S2'; 
  IF (vPARAM_CT=vSOURCE1 AND vSOURCE2=vPARAM_CT ) THEN
  BEGIN
    UPDATE table1 SET RUN_STATUS='COMPLETED' WHERE call_id='C001' ;
  END;
  ELSE
  BEGIN
  UPDATE table1 SET RUN_STATUS='COMPLETE WITH MISSING COUNTRY CODE' WHERE call_id='C001'  ;
  END;
  END IF;
  END;
  </code></pre>