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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:47:02+00:00 2026-05-16T05:47:02+00:00

I have a table that contains in one column a variable length delimited string

  • 0

I have a table that contains in one column a variable length delimited string for example:

20,0, 5,,^24,0, 0,,^26,0, 0,,^
281,0, 0,,^34,0, 2,,^48,0, 2,,^44,0, 2,,^20,0, 10,,^
20,5, 5,,^379,1, 1,,^26,1, 2,,^32,0, 1,,^71,0, 2,,^

What i need to do is split this string so that each number after the ^ character is returned on a new row. like:

Item Number Item Code
Item1 20
Item2 ^24
Item3 ^24
Item4 ^27
Item5 ^28
Item6 ^65
Item7 ^66
Item8 ^39
Item9 ^379
Item10 ^448
Item11 ^427

I’ve tried various split functions and I can manage to achieve the result i need by substring’ing the values across multiple columns and then using unpivot to return them across multiple rows however this method doesnt handle teh variable length of this string.

Any ideas of a better approach?

  • 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-16T05:47:03+00:00Added an answer on May 16, 2026 at 5:47 am

    First, let me just say that this is the reason that you shouln’t have comma separated data in a field in the first place. There is no easy or efficient way to work with it.

    That said, you can use a recursive query to split the string and get the numbers from it:

    with split as
    (
      select
        item = cast('' as varchar(max)),
        source = cast('20,0, 5,,^24,0, 0,,^26,0, 0,,^281,0, 0,,^34,0, 2,,^48,0, 2,,^44,0, 2,,^20,0, 10,,^20,5, 5,,^379,1, 1,,^26,1, 2,,^32,0, 1,,^71,0, 2,,^' as varchar(max))
      union all
      select
        item = substring(source, 1, charindex(',,', source)),
        source = substring(source, charindex(',,', source) + 2, 10000)
      from split
      where source > ''
    )
    select substring(item, 1, charindex(',', item) -1)
    from split
    where item > ''
    

    Result:

    20
    ^24
    ^26
    ^281
    ^34
    ^48
    ^44
    ^20
    ^20
    ^379
    ^26
    ^32
    ^71
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TABLE elements with one COLUMN number, type SMALLINT that contains numbers
I have a table (lets say it has one column called 'colLanguage') that contains
I have a table that contains millions of records. I'm altering one column data
In my SQL 2008 database table, I have one column name AUTHOR that contains
I have one table with name CateringPurchaseOrder. That table contains one column with name
I have a table that contains the following columns: @Column(name=CTDESTATUS) private String status; @Column
Here is my situation: I have one table that contains a list of drugs
I have a table that contains common entries in two columns. For Example: Column1
I have a table that contains an Id column as a primary key. There
I have a .sqlite db which contains only one table. That table contains three

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.