title: Error SQLCODE -138 when doing a trigger in DB2
body: <p>I get the following error trying to create a stored procedure in DB2</p>
  
  <pre><code>Error report:
  DB2 SQL error: SQLCODE: -138, SQLSTATE: 22011, SQLERRMC: null
  </code></pre>
  
  <p>My trigger is the following one:</p>
  
  <pre><code>CREATE TRIGGER INSERT_SERIALNUMBER
  AFTER INSERT ON LASERM
  REFERENCING NEW ROW AS NROW
  FOR EACH ROW MODE DB2SQL
  BEGIN
  DECLARE ARTICLECODE CHAR(30); 
  DECLARE POS INT;
  SET POS = LOCATE('-', NROW.PROGRAMNAME);
  
  IF POS &gt; 0 THEN
    SET ARTICLECODE = SUBSTR(NROW.PROGRAMNAME, 0, POS);
  ELSE
    SET ARTICLECODE = NROW.PROGRAMNAME;
  END IF;
  CALL SP_INSERT_SERIALNUMBER(ARTICLECODE, NROW.PCBCODE);
  END
  </code></pre>
  
  <p>According to the DB2 SQLCodes list, -138</p>
  
  <pre><code>-138 THE SECOND OR THIRD ARGUMENT OF THE SUBSTR OR SUBSTRING FUNCTION IS OUT OF RANGE
  </code></pre>
  
  <p>What I want to do is to substract a string from another when it finds a "-". For example, the code is "ART00001-A" and I would like to get just "ART00001".</p>
  
  <p>I'm not an expert in DB2 SQL syntax, so please,thanks in advance if you see the problem in that code.</p>