title: SQL: Perform arithmetic operations on values in a column
body: <p>I have a <code>varchar</code> that contains a formula:</p>
  
  <pre><code>declare @formula varchar(50) = 'X + Y + Z'
  </code></pre>
  
  <p>and I also have a table:</p>
  
  <pre><code>+---+---+
  | A | B |
  +---+---+
  | X | 1 |
  +---+---+
  | Y | 2 |
  +---+---+
  | Z | 3 |
  +---+---+
  </code></pre>
  
  <p>Column A values are unique and the formula may change. For example, if the formula is set to <code>'X + Y + Z'</code> then the result would be 6. And if the formula is set to <code>'Z - X + Y'</code> then the result is 4. Operations include only addition and subtraction. How can I achieve this? Having a hard time looking for where to start.</p>