Is there a way to get a value of a local variable specified by its name dynamically in SQL Server SP?
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
eval won't help since it does not have access to local variables of the enclosing scope.
I'm doing this for debugging/diagnostics purposes mostly.