title: Split comma delimited parameter being passed to stored procedure in SQL Server 2008 R2
body: <p>I am being passed the following parameter to my stored procedure -</p>
  
  <pre><code>@AddOns = 23:2,33:1,13:5
  </code></pre>
  
  <p>I need to split the string by the commas using this -</p>
  
  <pre><code>SET @Addons = @Addons + ','
  set @pos = 0
  set @len - 0
  
  While CHARINDEX(',', @Addons, @pos+1)&gt;0
  Begin
       SET @len = CHARINDEX(','), @Addons, @pos+1) - @pos
       SET @value = SUBSTRING(@Addons, @pos, @len)
  </code></pre>
  
  <p>So now @value = 23:2 and I need to get 23 which is my ID and 2 which is my quantity. Here is the rest of my code -</p>
  
  <pre><code>INSERT INTO TABLE(ID, Qty)
  VALUES(@ID, @QTY)
  
  set @pos = CHARINDEX(',', @Addons, @pos+@len) + 1
  END
  </code></pre>
  
  <p>So what is the best way to get the values of 23 and 2 in separate fields to us in the <code>INSERT</code> statement?</p>