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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:58:41+00:00 2026-06-09T05:58:41+00:00

I can do this using cursors, but I’m trying to avoid it if at

  • 0

I can do this using cursors, but I’m trying to avoid it if at all possible. Here’s a bit of sample code that I’ve got going:

declare @string varchar(max) = 'person1:item1~item2~item3~etc^person2:item1~item2~item3~etc'

declare @table1 table (id int, value varchar(500))
declare @table2 table (id varchar(50), value varchar(500))
declare @table3 table (id varchar(50), value varchar(50))

insert @table1 (id, value) select * from fn_ParseDelimitedStrings(@string, '^')

insert @table2 (id, value) 
    select 
        id = (select f.value from fn_ParseDelimitedStrings(t.value, ':') f where f.RowId=1),
        value = (select f.value from fn_ParseDelimitedStrings(t.value, ':') f where f.RowId=2)
    from @table1 t

select * from @table2

The above code gives me the data in the form of:

id        value
-------------------------------
person1   item1~item2~item3~etc
person2   item1~item2~item3~etc

But I need the data in this form:

id        value
-------------------------------
person1   item1
person1   item2
person1   item3
person1   etc
person2   item1
person2   item2
person2   item3
person3   etc

The input string can have any number of “persons”, and each person can have any number of “items”.

fn_ParseDelimitedStrings is a custom function we have that returns a table of index-value pairs for each delimited item. ie:

RowID   Value
-------------
1       item1
2       item2
3       item3
4       etc

I’m having trouble associating each “item” from the final split to the “person” that they should be associated with.

Is there anything that can be done or am I going to have to use a cursor?

  • 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-09T05:58:42+00:00Added an answer on June 9, 2026 at 5:58 am

    outer apply will join current row with all the rows found in derived table inside outer apply:

    insert @table2 (id, value) 
    select 
        id = (select f.value from fn_ParseDelimitedStrings(t.value, ':') f where f.RowId=1),
        value = v1.value
    from @table1 t
    outer apply
    (
      select v.value
        from fn_ParseDelimitedStrings(
             (select f.value 
                from fn_ParseDelimitedStrings(t.value, ':') f 
               where f.RowId=2)
             , '~') v 
    ) v1
    

    *Edited value1 to v1 to match the outermost select

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

Sidebar

Related Questions

I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I am using http://uniformjs.com for my html controls. We can apply this using code
I can do this easily using a TextBoxFor but how do I do it
I'm having this argument about using Cursors in TSQL recently... First of all, I'm
Using this: Can I use Facebook's fb:friend-selector in an iframe? I created a multi-friend
How can I do this using CSS and HTML? Bordered text surrounded by colored
Not sure if yall can help this time, as I'm just using this particular
I am not using boost libraries. How can i do this using STL? class
Given this XML: <Items> <Item>a</Item> <Item>b</Item> </Items> How can I deserialize this using XmlSerializer
[1,2,3].forEach(function(el) { if(el === 1) break; }); How can I do this using the

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.