title: How to calculate dynamically a column containing a formula in SQL Server a return the value
body: <p>I've been searching for this but I dont know how to ask for this specific information. </p>
  
  <p>Lets imagine I have something like this in  my sql table. </p>
  
  <pre><code>Columns:
  width : 10
  height: 15
  Depth: 6
  </code></pre>
  
  <p>And I have a formula column like this</p>
  
  <pre><code>formula: (W*2)+H+D+3
  </code></pre>
  
  <p>where I replace W with Width, H with Height, and D with depth.
  using sql Replace, I am able to do this and convert the final result as</p>
  
  <pre><code>(10*2)+15+6+3
  </code></pre>
  
  <p>The problem is that I need the calculation to be done in the column as a result. </p>
  
  <p>I tried this direcly in SQL</p>
  
  <pre><code>select 1 as width , 
  2 as height , 
  3 as depth , 
  'H*2+W' as formula,
  replace(Replace(REPLACE('H*2+W','W',1),'H',2),'D',3) as result
  </code></pre>
  
  <p>I need to be able to do this directly in the query, and calculate each row result with its specific value.</p>
  
  <p>I tried doing Execs inside Select, but no luck. this would run 1000 querys if my initial query has 1000 rows... </p>
  
  <p>How can I make this the best possible way?</p>