title: sql server query to replace variables with values recursively
body: <p>I have a table <code>variable</code> containing variables names and their values, for example :</p>
  
  <ul>
  <li>var1 = value1</li>
  <li>var2 = value2</li>
  <li>var3 = value3</li>
  </ul>
  
  <p>Another table <code>expression</code> contains expressions :</p>
  
  <ul>
  <li>"a string using #var1# and #var2#"</li>
  <li>"another one with #var3# and #var4# and even #var1#" </li>
  </ul>
  
  <p>and I want to replace the variables present in the table <code>variable</code> by their values, so the result should be : </p>
  
  <ul>
  <li>"a string using value1 and value2"</li>
  <li>"another one with value3 and #var4# and even value1"</li>
  </ul>
  
  <p>Is there a way to do this with a CTE ?</p>
  
  <p><a href="http://sqlfiddle.com/#!3/c1e1e/2/0" rel="nofollow">http://sqlfiddle.com/#!3/c1e1e/2/0</a></p>