Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:58:15+00:00 2026-06-18T15:58:15+00:00

I am having a stored procedure which gets the comma separated value as an

  • 0

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.

Let the input for SP is :

Rule_ID  ListType_ID  Values
1        2            319,400,521,8465,2013

I need to store it in a table called DistributionRule_x_ListType in the below format:

Rule_ID  ListType_ID  Value
1        2            319
1        2            400
1        2            521
1        2            8465
1        2            2013

My SP looks like below:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:58:17+00:00Added an answer on June 18, 2026 at 3:58 pm

    You will need to create a split function similar to this:

    create FUNCTION [dbo].[Split](@String varchar(MAX), @Delimiter char(1))       
    returns @temptable TABLE (items varchar(MAX))       
    as       
    begin      
        declare @idx int       
        declare @slice varchar(8000)       
    
        select @idx = 1       
            if len(@String)<1 or @String is null  return       
    
        while @idx!= 0       
        begin       
            set @idx = charindex(@Delimiter,@String)       
            if @idx!=0       
                set @slice = left(@String,@idx - 1)       
            else       
                set @slice = @String       
    
            if(len(@slice)>0)  
                insert into @temptable(Items) values(@slice)       
    
            set @String = right(@String,len(@String) - @idx)       
            if len(@String) = 0 break       
        end   
    return 
    end;
    

    Then in your stored procedure, you will call the function to split your string:

    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)
        SELECT @Rule_ID, @ListType_ID, items
        FROM [dbo].[Split] (@Values, ',')  -- call the split function 
    
    END
    

    When you execute the stored procedure, it will split the values and insert the multiple rows into your table:

    exec spInsertDistributionRuleListType 1, 2, '319,400,521,8465,2013';
    

    See SQL Fiddle with Demo. This will insert the following result:

    | RULE_ID | LISTTYPE_ID | VALUE |
    ---------------------------------
    |       1 |           1 |    10 |
    |       1 |           2 |   319 |
    |       1 |           2 |   400 |
    |       1 |           2 |   521 |
    |       1 |           2 |  8465 |
    |       1 |           2 |  2013 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure inside which I create a temporary table that typically
i am having a stored procedure in sql server which returns a variable of
Morning People, I'm having a little issue with COALESCE causing a stored procedure which
I need to create a sql stored procedure (Sql Server 2008 - T-SQL) which
Hi I am writing a large stored procedure, which creates a dynamic report table,
I have a weird requirement which I need to use inside my Stored Procedure
I'm having problems passing a null value to a stored procedure, e.g. if an
I m using a stored procedure and there i m having a column Name
I am having a basic mysql stored procedure for inserting user data along with
I am having the below statement from stored procedure. It's giving Insufficient Privileges. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.