title: How can I convert the division of two integer values to a decimal using T-SQL against a iSeries AS/400 Database?
body: <p>Assuming the following query:</p>
  
  <pre><code>SELECT
      ID,
      COUNT(1) AS NumRecords,
      SUM(Quantity) AS TotalQty
      SUM(Quantity)/COUNT(1) AS Avg
  FROM        SOME_TABLE
  GROUP BY    ID
  </code></pre>
  
  <p>Right now it returns:</p>
  
  <pre><code>ID    NumRecords    TotalQty    Avg
  1     15            6           2
  </code></pre>
  
  <p>I want it to return a decimal value with a Scale of 2 for <code>Avg</code> (i.e. "2.5").</p>
  
  <p>I've tried to <code>CAST</code> the calcluation as a DECIMAL, NUMERIC, FLOAT, and VARCHAR, but it always returns an INTEGER.</p>