title: How to store mathematical formula in MS SQL Server DB and interpret it using JAVA?
body: <p>I have to give the user the option to enter in a text field a mathematical formula and then save it in the DB as a String. That is easy enough, but I also need to retrieve it and use it to do calculations. </p>
  
  <p>For example, assume I allow someone to specify the formula of employee salary calculation which I must save in String format in the DB. </p>
  
  <pre><code>GROSS_PAY = BASIC_SALARY - NO_PAY + TOTAL_OT +  ALLOWANCE_TOTAL
  </code></pre>
  
  <p>Assume that terms such as GROSS_PAY, BASIC_SALARY are known to us and we can make out what they evaluate to. The real issue is we can't predict which combinations of such terms (e.g. GROSS_PAY etc.) and other mathematical operators the user may choose to enter (not just the +, -, ×, / but also the radical sigh - indicating roots - and powers etc. etc.). So how do we interpret this formula in string format once where have retrieved it from DB, so we can do calculations based on the composition of the formula. </p>