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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:35:11+00:00 2026-06-15T05:35:11+00:00

I have strings in a database table like this: Peter/Parker/Spiderman/Marvel Bruce/Wayne/Batman/DC Is there a

  • 0

I have strings in a database table like this:

Peter/Parker/Spiderman/Marvel
Bruce/Wayne/Batman/DC

Is there a way in SQL to extract specific values from a string e.g.

Name = MyColumn(0)
SurName = MyColumn(1)
Character = MyColumn(3)
Company = MyColumn(4)

Thanks

  • 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-15T05:35:12+00:00Added an answer on June 15, 2026 at 5:35 am

    If you know you will have exactly 4 columns, then you can also use this nested CTE version:

    ;with s1 (name, extra) as
    (
      select left(data, charindex('/', data)-1), 
        substring(data, charindex('/', data) +1, len(data))
      from yourtable
    ),
    s2 (name, surname, extra) as
    (
      select name, 
        left(extra, charindex('/', extra)-1), 
        substring(extra, charindex('/', extra)+1, len(extra))
      from s1
    ),
    s3 (name, surname, [character], company) as
    (
      select name, 
        surname, 
        left(extra, charindex('/', extra)-1), 
        substring(extra, charindex('/', extra)+1, len(extra))
      from s2
    )
    select *
    from s3;
    

    See SQL Fiddle with Demo

    The result is:

    |  NAME | SURNAME | CHARACTER | COMPANY |
    -----------------------------------------
    | Peter |  Parker | Spiderman |  Marvel |
    | Bruce |   Wayne |    Batman |      DC |
    

    Or you can implement both a CTE that splits the data and then a PIVOT:

    ;with cte (item, data, colNum, rn) as
    (
      select cast(left(data, charindex('/',data+'/')-1) as varchar(50)) item,
        stuff(data, 1, charindex('/',data+'/'), '') data,
        1 colNum,
        row_number() over(order by data) rn
      from yourtable
      union all
      select cast(left(data, charindex('/',data+'/')-1) as varchar(50)) ,
        stuff(data, 1, charindex('/',data+'/'), '') data,
        colNum+1, 
        rn
      from cte
      where data > ''
    ) 
    select [1] as Name, 
      [2] as Surname, 
      [3] as [character], 
      [4] as company
    from
    (
      select item, colnum, rn
      from cte
    ) src
    pivot
    (
      max(item)
      for colnum in ([1], [2], [3], [4])
    ) piv
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

I have this strings saved in my mysql database in format like: /uploads/attachments/18/105/WordPress_3_Cookbook.pdf Now,
I have multiple web services that write data inside a database table. I'd like
I have rows in a contact details database that look like this: contactID -
I have a database table that contains Swedish/Norwegian strings. When I query some data,
I have questions which are represented like this in my SQL database : CREATE
Maybe there was a better way to do this, but I have a list
I have sets of strings in a database. Each set will have less than
I have to store long strings in MySQL database using spring roo. I assumed
I have more than 100 million unique strings (VARCHAR(100) UNIQUE in MySQL database). Now
I have the following data in my database (comma separated strings): word, test, hello

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.