title: How to use column in result set as parameter to FROM clause in a SELECT
body: <p>I have result set stored in a variable like this</p>
  
  <pre><code>DECLARE @tmpTable TABLE([table] sysname, [column] sysname);
  INSERT INTO @tmpTable
      SELECT tab1.name AS [table],
          col1.name AS [column] 
      FROM sys.foreign_key_columns fkc
       INNER JOIN sys.objects obj
        ON obj.object_id = fkc.constraint_object_id
       INNER JOIN sys.tables tab1
        ON tab1.object_id = fkc.parent_object_id
       INNER JOIN sys.schemas sch
        ON tab1.schema_id = sch.schema_id
       INNER JOIN sys.columns col1
        ON col1.column_id = parent_column_id AND col1.object_id = tab1.object_id
       INNER JOIN sys.tables tab2
        ON tab2.object_id = fkc.referenced_object_id
       INNER JOIN sys.columns col2
        ON col2.column_id = referenced_column_id AND col2.object_id = tab2.object_id
  WHERE tab2.name = 'sometable'
  </code></pre>
  
  <p>This gives me a result set like this:</p>
  
  <pre><code>| table | column |
  |-------|--------|
  | tab1  | col4   |
  | tab2  | col12  |
  | tab2  | col1   |
  </code></pre>
  
  <p>What I need now is to query each table from the above result set and get the value of the column 'column' from that table. </p>