title: separate comma separated values and store in table in sql server
body: <p>I am having a stored procedure which gets the comma separated value as an input. I need to separate it and needs to store it in a table as individual rows.</p>
  
  <p>Let the input for SP is : </p>
  
  <pre><code>Rule_ID  ListType_ID  Values
  1        2            319,400,521,8465,2013
  </code></pre>
  
  <p>I need to store it in a table called <code>DistributionRule_x_ListType</code> in the below format:</p>
  
  <pre><code>Rule_ID  ListType_ID  Value
  1        2            319
  1        2            400
  1        2            521
  1        2            8465
  1        2            2013
  </code></pre>
  
  <p>My SP looks like below:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[spInsertDistributionRuleListType]
  (@Rule_ID int,
  @ListType_ID int,
  @Values VARCHAR(MAX)=NULL
  )
  AS
  BEGIN
  
      INSERT INTO DistributionRule_x_ListType (Rule_ID,ListType_ID,Value)
      VALUES (@Rule_ID,@ListType_ID,@Values)
  
  END
  </code></pre>