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 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 this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I have stored the XML path to items in a string like this: response->items->item
I have a parameter string that passes date value to a stored proc cmdItemSearch.Parameters.Add(new
I have an email body stored as a string in a database, something like
I have a Stored Proc query below which involves returning partial delimited search string.
I have a stored proc that takes a date a string parameter. The data
I have a dataset that gets populated from a stored proc in sql server.
i have string stored in python variables, and i am outputting a html that
In my applications web.config file I have a connection string stored. I encrypted it
I have a variable, emailBody, which is set to a string stored in a

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.