title: SQL Server decimal scale length - can be or has to be?
body: <p>I have really simply question about <code>DECIMAL</code> (and maybe <code>NUMERIC</code>) type in SQL Server 2008 R2.</p>
  
  <p><strong>MSDN said:</strong></p>
  
  <blockquote>
    <p>(scale)
    The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p.</p>
  </blockquote>
  
  <p>I understand this following way:</p>
  
  <ul>
  <li>if I have <code>DECIMAL(10, 5)</code> - I am able to store 12345.12345 or 12345678.91.</li>
  <li>if I have <code>DECIMAL(5, 5)</code> - I can have 12345 or 1234.5 or 1.2345, etc...</li>
  </ul>
  
  <p>Is it clear?</p>
  
  <p>But I got this error message:</p>
  
  <pre><code>SELECT CAST(2.8514 AS DECIMAL(5,5))
  </code></pre>
  
  <blockquote>
    <p>Arithmetic overflow error converting numeric to data type numeric.</p>
  </blockquote>
  
  <p>I thought 5,5 means I can have up to 5 digits and up to 5 CAN BE right of the decimal point.</p>
  
  <p>As I tried:</p>
  
  <pre><code>SELECT CAST(12.851 AS DECIMAL(6,5)) - overflows too
  </code></pre>
  
  <p><strong>however</strong></p>
  
  <pre><code>SELECT CAST(1.23456 AS DECIMAL(6,5)) - is OK.
  </code></pre>
  
  <p>So what's the truth?</p>
  
  <p><code>DECIMAL(a,b)</code> says that I can have up to a digits and JUST b of them are right to the decimal point (and there rest a-b to the left to the dec. point)?</p>
  
  <p>I'm really confused about statement in doc which is copied everywhere. Please take a while and explain me this simple thing.</p>
  
  <p>Lot of thanks!</p>