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 431077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:56:19+00:00 2026-05-12T19:56:19+00:00

My data looks as follows MyText ——- some text, some more text, even more

  • 0

My data looks as follows

MyText
-------
some text, some more text, even more text,,
some text,,,,
some text, some text,,,
some text, some more text, even more, yet more, and again

I would like to achieve:

MyText
-------
some text, some more text, even more text
some text
some text, some text
some text, some more text, even more, yet more, and again

How can I remove the commas at the end of the lines? I must retain the commas between items, but I need to remove any from the end

I need to do this within a select statement, and I haven’t been able to find a solution of applying a RegEx without writing a function (Which I would prefer to avoid)

I have one solution, but its particulary dirty and I would like to improve it. I’m using a set of nested REPLACE to replace 4 commas with 3, 3 with 2, and 2 with one, then remove the end one

Any ideas?

EDIT: Data is coming from an external system, so I have no control over that, otherwise I’d concatenate with commas correctly in the first instance. This statement I’m using will be run on SQL Server 2005

  • 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-12T19:56:20+00:00Added an answer on May 12, 2026 at 7:56 pm

    Try something like this

    DECLARE @Table TABLE(
            Val VARCHAR(MAX)
    )
    
    INSERT INTO @Table (Val)  SELECT 'some text, some more text, even more text,,'
    INSERT INTO @Table (Val)  SELECT 'some text,,,,'
    INSERT INTO @Table (Val)  SELECT 'some text, some text,,,'
    INSERT INTO @Table (Val)  SELECT 'some text, some more text, even more, yet more, and again'
    
    SELECT  Val,
            REVERSE(SUBSTRING(  REVERSE(Val),   PATINDEX('%[A-Za-z0-9]%',REVERSE(Val)), LEN(VAL) - (PATINDEX('%[A-Za-z0-9]%',REVERSE(Val)) - 1) ) ),
            *
    FROM    @Table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse data from Archive.org's search functionality. The data looks like this:
A Report can have multiple charts. The Chart table looks as follows: Chart --
My scenario is as follows: I have a table of data (handful of fields,
I'm trying to populate a template with variables from a database. The data looks
We're creating a system outputting some data to an XML schema. Some of the
I need to create a configuration file from a data file that looks as
I have an enum that looks as follows: public enum TransactionStatus { Open =
I have a OdbcDataReader that gets data from a database and returns a set
I have a table listing people along with their date of birth (currently 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.