title: Locate Cause of IBM DB2 CAST Failure
body: <p>I need to work on an IBM DB2 database.</p>
  
  <p>The <code>LOCATION</code> field is a <code>CHARACTER(8)</code> field of numbers.</p>
  
  <p>To sort the table, the column is cast to an <code>INTEGER</code>:</p>
  
  <pre><code>SELECT LOCATION, PARTNO, INSTOCK 
  FROM INVENTORY
  ORDER BY CAST(LOCATION AS INTEGER)
  </code></pre>
  
  <p>Currently, this fails with:</p>
  
  <blockquote>
    <p>ERROR [22018] [IBM][DB2/AIX64] SQL0420N Invalid character found in a character string argument of the function "INTEGER".</p>
  </blockquote>
  
  <p>Is there a quick way to determine which row is failing?</p>
  
  <p><a href="http://www-01.ibm.com/support/docview.wss?uid=swg21367400" rel="nofollow">IBM's solution</a> is to <em>"Insure that the results set for the query item that the cast it being applied to does not contain non numeric SQL constants when casting to a numeric type."</em></p>
  
  <p>That wasn't really helpful.</p>
  
  <p>Thinking someone inserted a letter O or lower case L, I tried this:</p>
  
  <pre><code>SELECT DISTINCT LOCATION 
  FROM LOCATIONS 
  WHERE LOCATION LIKE '%l%' OR LOCATION LIKE '%O%'
  ORDER BY LOCATION
  </code></pre>
  
  <p>Zero records returned.</p>