title: How to use the result of SQL aggregate in IF statement
body: <p>I am trying to script a procedure in HANA, and I have a requirement to compare the Week ID's of 2 tables. If the <code>Week ID1 &gt; Week ID2</code>, I have to insert the new records to table which has ID2. I tried the below logic, but that did not work. </p>
  
  <p>Here, the logic inside the <code>IF</code> is not executing, though the </p>
  
  <pre><code>VAR1 VARCHAR(2);
  VAR2 VARCHAR(2);
  BEGIN
      SELECT MAX(FISCAL_WK) AS VAR1 FROM "XXX"."OUTLOOK_FACTS";
      SELECT MAX(FISCAL_WK) AS VAR2 FROM "XXX"."OUTLOOK";
      IF :VAR2 &gt; :VAR1 THEN
          SELECT MAX(OUTLOOKID) AS TEST FROM "XXX"."OUTLOOK_FACTS";
      END IF;
  END;
  </code></pre>
  
  <p>I am pretty new to this, so please help.</p>