Join two Select Statements into a single row when one select has n amount of entries?
<p>Is it possible in SQL Server to take two select statements and combine them into a single row without knowing how many entries one of the select statements got?</p>

<p>I've been looking around at various Join solutions but they all seem to work on the basis that the amount of columns is predetermined. I have a case here where one table has a determined amount of columns (t1) and the other table have an undetermined amount of entries (t2) which all use a key that matches one entry in t1.</p>

<pre><code>+----+------+-----+
| id | name | ... |
+----+------+-----+
|  1 | John | ... |
+----+------+-----+
</code></pre>

<p>And</p>

<pre><code>+-------------+----------------+
| activity_id | account_number |
+-------------+----------------+
| 1           | 12345467879    |
| 1           | 98765432515    |
| ...         | ...            |
| ...         | ...            |
+-------------+----------------+
</code></pre>

<p>The number of account numbers belonging to the first query is unknown.</p>

<p>After the query it would become:</p>

<pre><code>+----+------+-----+----------------+------------------+-----+------------------+
| id | name | ... | account_number | account_number_2 | ... | account_number_n |
+----+------+-----+----------------+------------------+-----+------------------+
|  1 | John | ... |    12345467879 |      98765432515 | ... | ...              |
+----+------+-----+----------------+------------------+-----+------------------+
</code></pre>

<p>So I don't know how many account numbers could be associated with the id beforehand.</p>