title: IF EXISTS statement alternative in HANA
body: <p>I want looked for "if exists", but sap hana sql was not understand for "if exists". whether i was created sql-command wrong. </p>
  
  <p>If 'Y' for the record exists in table from ZZZ_Exercise_3, else 'N' for the record not exists in table from ZZZ_Exercise_3. If old record for 'N' then this record delete should.    </p>
  
  <pre><code> CREATE COLUMN TABLE ers.ZZZ_EXERCISE_5(
      ID INT NOT NULL PRIMARY KEY generated by default as IDENTITY,
      Orig_ID INT,
      COMPANY nvarchar(251),
      VALID char(1)
  );
  
  COMMIT;
  
  IF EXISTS(
      INSERT INTO ZZZ_EXERCISE_5(Orig_ID, COMPANY, VALID)
      SELECT ID, COMPANY, 'Y' FROM ZZZ_EXERCISE_3
  )
  ELSE(
      INSERT INTO ZZZ_EXERCISE_5(Orig_ID, COMPANY, VALID)
      SELECT ID, COMPANY, 'N' FROM ZZZ_EXERCISE_3
  )
  
  COMMIT;
  
  UPDATE ZZZ_EXERCISE_3
  SET COMPANY = (SELECT COMPANY FROM ERS.ZZZ_EXERCISE_5)
  WHERE NOT EXISTS (SELECT COMPANY FROM ZZZ_EXERCISE_5 WHERE ZZZ_EXERCISE_5.VALID = 'N')
  
  COMMIT;
  
  DELETE FROM ZZZ_EXERCISE_3
  WHERE ERS.ZZZ_EXERCISE_5.VALID = 'N'
  
  SELECT * FROM ZZZ_EXERCISE_3
  WHERE NOT EXISTS (SELECT COMPANY FROM ZZZ_EXERCISE_5 WHERE ZZZ_EXERCISE_5.ID = ZZZ_EXERCISE_3.ID)
  </code></pre>