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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:22:14+00:00 2026-05-16T06:22:14+00:00

I currently have a code table containing a list of types (Type_ID, Description), but

  • 0

I currently have a code table containing a list of types (Type_ID, Description), but they are saved in another table as ID;;ID;;ID…etc

I am looking for a script that will take those ID’s and place them in a relationship table corresponding to there Type ID

For example in table A the Type_ID entries could look like:

1;;2;;4
1
3;;4
1;;2;;3;;4

I am completely stumped on how to accomplish this and any help is appreciated.

  • 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-16T06:22:15+00:00Added an answer on May 16, 2026 at 6:22 am

    First of all, I would probably recommend going the UDF route (so that you don’t reinvent the wheel). However, given that this sounds like a one-off activity, you could just use the following:

    declare @output table (parentKey int, value int)
    
    declare @values table (idx int identity(1, 1), parentKey int, value varchar(255))
    
    -- Modify the below query to capture the data from your table
    insert into @values (parentKey, value) values(1, '1;;2;;4'),(2, '1'),(3, '3;;4'),(4, '1;;2;;3;;4')
    
    declare @i int
    declare @cnt int
    
    select @i = MIN(idx) - 1, @cnt = MAX(idx) from @values
    
    while(@i < @cnt)
    begin
        select @i = @i + 1
    
        declare @value varchar(255)
        declare @key int
    
        select @value = value, @key = parentKey from @values where idx = @i
    
        declare @idx int
        declare @next int
    
        select @idx = 1
    
        while(@idx <= LEN(@value))
        begin
            select @next = CHARINDEX(';;', @value, @idx)
    
            if(@next > @idx)
            begin
                insert into @output (parentKey, value) values(@key, SUBSTRING(@value, @idx, @next - @idx))
    
                select @idx = @next + 2
            end
            else
            begin
                insert into @output (parentKey, value) values(@key, SUBSTRING(@value, @idx, LEN(@value) - @idx + 1))
    
                select @idx = LEN(@value) + 1
            end
        end
    end
    
    select * from @output
    

    The @output table variable now contains the mapping you’re looking for. You can either copy from that to your destination at the end, or you can remove @output from the query and substitute equivalent inserts directly into your relationship table.

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

Sidebar

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.