you may refer to this
Create Proc GetValues(@ID as int)
As
BEGIN
Declare @SQL Nvarchar(max),@table nvarchar(30),@fieldname nvarchar(30)
select @table=table,@field name=fieldname from tblconfig where id=@ID
set @SQL='select '+@field name+' from '+@table
exec Sp_Execute @SQL
END