title: SQL Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=AS;FIRST 100 ROWS ONLY);), DRIVER=3.57.82
body: <p>The below DB2 stored procedure compiled successfully but getting runtime error <code>SQL Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=AS;FIRST 100 ROWS ONLY);), DRIVER=3.57.82</code></p>
  
  <p>Intention of the below db2 procedure is to delete the records from multiple tables with prepared statements.</p>
  
  <pre><code>CREATE PROCEDURE ALL_DATA_PURGE1(IN v_SCHEMA_NAME VARCHAR(24),IN v_DAYS INTEGER, IN v_COMMIT_COUNT INTEGER)
      NOT DETERMINISTIC
      LANGUAGE SQL
  BEGIN
  
      -- DECLARE Statements
      DECLARE SQLCODE INTEGER;
  
      DECLARE v_CRAD_DELETE_QUERY    VARCHAR(1024);
      DECLARE v_APPDATA_DELETE_QUERY VARCHAR(1024);
  
      DECLARE v_CRAD_DELETE_STATEMENT STATEMENT;
      DECLARE v_APPDATA_DELETE_STATEMENT STATEMENT;
  
      SET v_CRAD_DELETE_QUERY = 'DELETE FROM (SELECT 1 FROM ' || v_SCHEMA_NAME || '.CRAD WHERE UNIQUE_ID IN  
      (SELECT UNIQUE_ID FROM  ' || v_SCHEMA_NAME || '.APPDATA WHERE ORIGINATOR_TIMESTAMP &lt; (
        SELECT CURRENT TIMESTAMP - '|| v_DAYS ||' DAYS FROM SYSIBM.SYSDUMMY1)
        ) FETCH FIRST ' || v_COMMIT_COUNT || ' ROWS ONLY) AS DELETE_CRAD_TABLE';      
  
      SET v_APPDATA_DELETE_QUERY = 'DELETE FROM (SELECT 1 FROM ' || v_SCHEMA_NAME || '.APPDATA WHERE SOME_TIMESTAMP &lt; (
        SELECT CURRENT TIMESTAMP - ' || v_DAYS || ' days FROM sysibm.sysdummy1
        ) FETCH FIRST ' || v_COMMIT_COUNT || ' ROWS ONLY) AS DELETE_APPDATA_TABLE';
  
  
      PREPARE v_CRAD_DELETE_STATEMENT    FROM v_CRAD_DELETE_QUERY;  
      PREPARE v_APPDATA_DELETE_STATEMENT FROM v_APPDATA_DELETE_QUERY;
  
      DELETE_LOOP:
          LOOP
              EXECUTE v_CRAD_DELETE_STATEMENT;
              EXECUTE v_APPDATA_DELETE_STATEMENT;
  
              IF SQLCODE = 100 THEN
                  LEAVE DELETE_LOOP; 
              END IF;
              COMMIT;
          END LOOP;
  
     COMMIT;
  
  END
  </code></pre>