title: Get a value of a variable dynamically in SQL Server SP
body: <p>Is there a way to get a value of a local variable specified by its name dynamically in SQL Server SP?</p>
  
  <pre><code>declare @foo int
  declare @bar int
  
  declare @variable_name varchar(10)
  set @variable_name = '@foo'
  
  print -- magic happens here - how to print the value of the variable 
        -- which name is stored in @variable_name, in this case @foo
  </code></pre>
  
  <p><em>eval</em> won't help since it does not have access to local variables of the enclosing scope.</p>
  
  <p>I'm doing this for debugging/diagnostics purposes mostly.</p>