title: Extracting Fraction from Number stored as string
body: <p>I've got a field in this database that stores number like so:</p>
  
  <ul>
  <li>80 1/4 </li>
  <li>20 1/8 </li>
  <li>20 </li>
  <li>36 15/16 </li>
  <li>44 1/8 </li>
  <li>93 7/8 </li>
  <li>89 1/8</li>
  </ul>
  
  <p>I'm trying to convert these to a full decimal so I can add them up. I've been trying to do this by extracting the fraction out of the number, converting that to a decimal and then adding that to the whole number. I've been having some major problems extracting the numerator. The denominator has been extracted using:</p>
  
  <pre><code>CASE WHEN CHARINDEX('/',Fraction) &gt; 0 THEN RIGHT(Faction,(LEN(Fraction) - (CHARINDEX('/',Fraction)))) ELSE NULL END AS [Denominator]
  </code></pre>
  
  <p>I'm not sure if that's the most efficient way to do it but it seems to work. </p>
  
  <p>I've tried to pull the numerator out using this method:</p>
  
  <pre><code>CASE WHEN Charindex('/', Fraction) &gt; 0 THEN LEFT(RIGHT(Fraction, Len(Fraction) - Charindex(' ',Fraction)), CHARINDEX('/',Fraction) - 1) ELSE NULL END AS [Numerator]
  </code></pre>
  
  <p>But that just gives me the fraction itself. I'm not sure if SQL has a problem with a RIGHT inside a LEFT since it doesn't seem to do anything, or, more likely, my code is messed up.</p>
  
  <p>Anyone have any ideas?</p>
  
  <p>Thanks!</p>