title: T-SQL sum on decimal results in integer
body: <p>Alright, T-SQL isn't acting as I would expect.
  Look at this:</p>
  
  <pre><code>SELECT SUM(DEBET),SUM(CREDIT)
  CONVERT(DECIMAL(9,2),
      CASE WHEN SUM(DEBET) - SUM(CREDIT) &gt; 0.00
          THEN CONVERT(DECIMAL(9,2),SUM(CONVERT(DECIMAL(9,2),DEBET))) - CONVERT(DECIMAL(9,2),SUM(CONVERT(DECIMAL(9,2),CREDIT)))
          ELSE CONVERT(DECIMAL(9,2),0.00)
      END
  ) AS DEBETSALDO
  FROM OTHERTABLE
  </code></pre>
  
  <p><code>DEBET</code> and <code>CREDIT</code> in <code>OTHERTABLE</code> both are of type decimal; <code>DEBET(decimal,null)</code> according to the tooltip.</p>
  
  <p>The result is...</p>
  
  <pre><code>DEBET      CREDIT  DEBETSALDO
  6817.07    0.00    0
  </code></pre>
  
  <p>Why and where, if DEBET and CREDIT are interpreted as decimals, does SQL convert my whole shebang back to integer in this select statement?
  Maybe add a few more converters?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I just changed</p>
  
  <blockquote>
    <p>SELECT DEBET, CREDIT</p>
  </blockquote>
  
  <p>into</p>
  
  <blockquote>
    <p>SELECT SUM(DEBET), SUM(CREDIT)</p>
  </blockquote>
  
  <p>To emphasize where the problem lies. The results stay the same.</p>