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

  • Home
  • SEARCH
  • 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 4542652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:25:17+00:00 2026-05-21T15:25:17+00:00

I have a string in my stored proc like ‘,,,sam,,bob,’ or ‘,,,’ from the

  • 0

I have a string in my stored proc like ',,,sam,,bob,' or ',,,'
from the above string I have to delete multiple commas from it, it must look like
'sam,bob,' or only if ',,,' then '' .
I must use only Sql Server Functions.
Im using Sql Server 2008 and .Net 3.5

Thanks in advance.

  • 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-05-21T15:25:17+00:00Added an answer on May 21, 2026 at 3:25 pm

    This works for strings that are exclusively commas or have up to 398 contiguous commas.

     SELECT 
         CASE 
             WHEN TargetString NOT LIKE '%[^,]%' 
                 THEN '' /*The string is exclusively commas*/
             ELSE 
                REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TargetString,
                REPLICATE(',',16),','), /*399/16 = 24 remainder 15*/
                REPLICATE(',',8),','),  /* 39/ 8 =  4 remainder 7*/
                REPLICATE(',',4),','),  /* 11/ 4 =  2 remainder 3*/
                REPLICATE(',',2),','),  /*  5/ 2 =  2 remainder 1*/
                REPLICATE(',',2),',')   /*  3/ 2 =  1 remainder 1*/
             END
     FROM T    
    

    Add extra powers of 2 at the top if you need more or remove from the top if you need less. The comments by each stage indicate the smallest number that this stage will not deal with successfully.

    All the comment lines are in this format

    /*  L/D    =  Q remainder R */
    
    D:    Corresponds to the length of the string generated by `REPLICATE`
    R:    Is always D-1
    Q+R:  Form L for the next step
    

    So to extend the series upwards with another REPLICATE(',',32),',') stage

    D = 32 
    R = 31
    Q = 368 (399-31)
    L = (368 * 32) + 31 = 11807
    

    So that would deal with sections of commas up to 11,806 characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string coming from a table like can no pay{1},as your payment{2}due
ok so my issue is i have the string '\222\222\223\225' which is stored as
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have a string that has some Environment.Newline in it. I'd like to strip
I have a task of parsing a simple XML-formatted string in a MySQL stored
I have a quick linq question. I have a stored proc that should return
I have a very simple stored procedure which returns multiple record sets. All of
I have a SQL connection string being stored in the web.config. How can I
I have values stored as strings in a DataTable where each value could really
Overview: I have an array of 20 byte strings that needs to be stored

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.