title: Execute SQL-Query stored in column while selecting
body: <p>I have two tables:</p>
  
  <ul>
  <li>Table <code>A</code> contains the columns <code>ID</code> and <code>Query</code>. </li>
  <li>Table <code>B</code> contains the columns <code>ID</code>, <code>Value</code> and <code>Category</code>.</li>
  </ul>
  
  <p>In every row of table <code>A</code> (without any exceptions) the column <code>Query</code> contains an SQL query as nvarchar, which looks something like <code>SELECT * FROM B WHERE Category = 1</code>.</p>
  
  <p>I cannot figure out, how i can execute all Queries of table <code>A</code> and merge those results and return them (inside a select statement).</p>
  
  <p>I already tried to iterate through all rows in table <code>A</code>, inserting the results of <code>EXEC(Query)</code> into a temporary table <code>#C</code> and finally execute <code>SELECT * FROM #C</code>. But i was not successful with this solution.</p>
  
  <hr>
  
  <p><strong>EDIT</strong> </p>
  
  <p>Just for clarification: The columns and their data types of the resultsets of the queries - stored in table <code>A</code> -  are identical. Table <code>B</code> just has a column with datatype <a href="https://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx" rel="nofollow noreferrer"><code>[timestamp]</code></a>. The exception i receive is:</p>
  
  <blockquote>
    <p>Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column</p>
  </blockquote>