title: Execute table-valued function on multiple rows?
body: <p>Given a table-valued function such as <code>dbo.Split()</code> from <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-recor">"T-SQL: Opposite to string concatenation - how to split string into multiple records"</a>, how do I pass multiple rows as arguments?</p>
  
  <p>This works:</p>
  
  <pre><code>SELECT *
  FROM dbo.Split
    (',', (SELECT myColumn FROM Stuff WHERE id = 22268))
  WHERE ISNULL(s,'') &lt;&gt; ''
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>pn          s
  ----------- -----------
  1           22351
  2           22354
  3           22356
  4           22357
  5           22360
  </code></pre>
  
  <p>But this does not:</p>
  
  <pre><code>SELECT *
  FROM dbo.Split
    (',', (SELECT myColumn FROM Stuff))
  WHERE ISNULL(s,'') &lt;&gt; ''
  </code></pre>
  
  <p>Nor does this:</p>
  
  <pre><code>SELECT * FROM dbo.Split_temp(',', myColumn), Stuff
  </code></pre>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms175562.aspx" rel="noreferrer">The docs</a> say:</p>
  
  <blockquote>
    <p>When a user-defined function that returns a table is invoked in the FROM clause of a subquery, the function arguments cannot reference any columns from the outer query.</p>
  </blockquote>
  
  <p>The sort of result set I'm looking for would look something like:</p>
  
  <pre><code>id          pn          s
  ----------- ----------- -----------
  22268       1           22351
  22268       2           22354
  22268       3           22356
  22268       4           22357
  22268       5           22360
  24104       1           22353
  24104       2           22355
  24104       3           22356
  24104       4           22358
  24104       5           22360
  24104       6           22362
  24104       7           22364
  .
  .
  .
  </code></pre>
  
  <p>Is there any way at all (aside from, of course, a cursor) to accomplish this?</p>
  
  <p>(edit)</p>
  
  <p>As requested by MarlonRibunal, a sample table to produce the above result looks like:</p>
  
  <pre><code>id          myColumn
  ----------- -------------------------------------------
  22268       22351,22354,22356,22357,22360,
  24104       22353,22355,22356,22358,22360,22362,22364,
  </code></pre>
  
  <p><code>id</code> is an <code>int</code>; <code>myColumn</code> is a <code>varchar(max)</code>.</p>