title: Loop through a split string variable to insert rows in a stored procedure in SQL Server 2008
body: <p>I am working on SQL Server 2008 to create a stored procedure that:</p>
  
  <ol>
  <li>takes a string variable like this: <code>'1,2,3'</code></li>
  <li>splits the string using a table-valued function to get each value separately</li>
  <li>and then inserts each value into a new row in a table</li>
  </ol>
  
  <p>What I am trying to do is something like this:</p>
  
  <pre><code>WHILE (select vlaue FROM dbo.SplitString('1,2,3',',')) has rows
  insert into TableName (col1,col2) values (col1Data, value)
  </code></pre>
  
  <p>I am having a hard time trying to find the right syntax for this.</p>