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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:01:50+00:00 2026-06-05T06:01:50+00:00

I have a table like this: account | check1 | check2 1 | 100]200]300

  • 0

I have a table like this:

account   |   check1          |   check2
1         |   100]200]300     |   101]209]305
2         |   401]502         |   404]511
3         |   600             |   601

I want to separate the records into something like this:

account   |   check1     |   check2
1         |   100        |   101
1         |   200        |   209
1         |   300        |   305
2         |   401        |   404
2         |   502        |   511
.         |     .        |    .
.         |     .        |    .
.         |     .        |    .

How do I do this using SQL server only?

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-05T06:01:52+00:00Added an answer on June 5, 2026 at 6:01 am

    First, you need a split function that can allow you to determine order within the result. This is a multi-statement TVF which uses an IDENTITY column

    CREATE FUNCTION dbo.SplitStrings
    (
        @List       NVARCHAR(MAX),
        @Delimiter  NVARCHAR(255)
    )
    RETURNS @t TABLE(ID INT IDENTITY(1,1), Item INT)
    AS
    BEGIN
        INSERT @t(Item) SELECT SUBSTRING(@List, Number, 
            CHARINDEX(@Delimiter, @List + @Delimiter, Number) - Number)
        FROM (SELECT ROW_NUMBER() OVER (ORDER BY [object_id])
            FROM sys.all_objects) AS n(Number)
        WHERE Number <= CONVERT(INT, LEN(@List))
            AND SUBSTRING(@Delimiter + @List, Number, 1) = @Delimiter
        ORDER BY Number OPTION (MAXDOP 1);
    
        RETURN;
    END
    GO
    

    (If you have a Numbers table, you can use that instead of the subquery, and this will also allow you to add WITH SCHEMABINDING to the function’s definition, which provides potential performance benefits.)

    With the function in place, here is sample usage given the data you’ve provided and desired results:

    DECLARE @x TABLE(account INT, check1 NVARCHAR(1000), check2 NVARCHAR(1000));
    
    INSERT @x SELECT 1, '100]200]300','101]209]305'
    UNION ALL SELECT 2, '401]502','404]511'
    UNION ALL SELECT 3, '600','601'
    UNION ALL SELECT 4, '205]104','304]701'; -- I added this sanity check
    
    SELECT account, check1 = s1.Item, check2 = s2.Item
    FROM @x AS x
    CROSS APPLY dbo.SplitStrings(x.check1, ']') AS s1
    CROSS APPLY dbo.SplitStrings(x.check2, ']') AS s2
    WHERE s1.ID = s2.ID
    ORDER BY account, s1.ID;
    

    Results:

    account  check1  check2
    -------  ------  ------
    1        100     101
    1        200     209
    1        300     305
    2        401     404
    2        502     511
    3        600     601
    4        205     304
    4        104     701
    

    This assumes that you have some kind of validation / enforcement that corresponding values in check1 and check2 columns will always have the same number of values. It also assumes any check1 / check2 value will not exceed about 7,000 characters (again a Numbers table can help make that more flexible).

    EDIT

    After AndriyM’s comments I wanted to come back and re-visit this, mostly to supply a version of the above function which works without using a multi-statement TVF. This uses Andriy’s idea ROW_NUMBER() could be used.

    CREATE FUNCTION dbo.SplitStrings
    (
        @List       NVARCHAR(MAX),
        @Delimiter  NVARCHAR(255)
    )
    RETURNS TABLE
    AS
        RETURN (SELECT Number = ROW_NUMBER() OVER (ORDER BY Number),
            Item FROM (SELECT Number, Item = LTRIM(RTRIM(SUBSTRING(@List, Number, 
            CHARINDEX(@Delimiter, @List + @Delimiter, Number) - Number)))
        FROM (SELECT ROW_NUMBER() OVER (ORDER BY [object_id])
            FROM sys.all_objects) AS n(Number)
        WHERE Number <= CONVERT(INT, LEN(@List))
            AND SUBSTRING(@Delimiter + @List, Number, 1) = @Delimiter
        ) AS y);
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100
I have something like this: create table account ( id int identity(1,1) primary key,
I have a table with several account fields like this: MAIN_ACCT GROUP_ACCT SUB_ACCT I
I have a table sorted like this: id tag account 0 sport 123 1
I have a table like this: date_start date_end account_id product_id 2001-01-01 2001-01-31 1 1
I have table like this: +------+-------+ | user | data | +------+-------+ | 1
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have table design like this: id_a int(10) NO PRI id_b int(10) NO PRI
I have a table like this. (BIGINT) (BIGINT) PLAYER_ID FRIEND_ID ---------------------- 1 2 2
I have a table like this: column_a column_b foo 1 bar 1 bar 2

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.