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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:26:22+00:00 2026-06-12T00:26:22+00:00

I need to split a string in sql server and insert the data in

  • 0

I need to split a string in sql server and insert the data in a table.
Te string is fixed length, no comma separated. In the string I can have 1 or more records to insert, for example:

id = 2 characters
name = 4 characters

string: 01AAAA02BBBB03CCCC.

In this example I have 3 records to insert (I can have only one record or more in the string)

id Name
01 AAAA
02 BBBB
03 CCCC

I need a way to split this info in two different columns and in three different rows. I was thinking to use BCP utility but I’m not sure, maybe I need to split and generate a file and then use BCP.

Any idea?

  • 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-12T00:26:23+00:00Added an answer on June 12, 2026 at 12:26 am

    The following will handle more than 3 id/name pairs. Note however, that there is no error checking. I leave that to you.

    DECLARE @Input NVARCHAR(18)
    SET @Input = '01AAAA02BBBB03CCCC'
    
    DECLARE @Data TABLE 
    (
        [Id] NCHAR(2),
        [Name] NCHAR(4)
    )
    
    WHILE LEN(@Input) > 0
    BEGIN
    
        DECLARE @CurrentData NCHAR(6)
        SET @CurrentData = LEFT(@Input, 6)  
    
        DECLARE @CurrentId NCHAR(2)
        SET @CurrentId = LEFT(@CurrentData, 2)  
    
        DECLARE @CurrentName NCHAR(4)
        SET @CurrentName = RIGHT(@CurrentData, 4)   
    
        INSERT INTO @Data
        (
            [Id],
            [Name]
        )
        SELECT
            @CurrentId,
            @CurrentName
    
        SET @Input = RIGHT(@Input, LEN(@Input) - 6)
    
    END
    
    SELECT 
        [Id],
        [Name]
    FROM
        @Data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to split comma delimited string into a second columns I have the
I have a SQL table with column which contain string like 'type|type1|type2|type3|type4'. I need
I have a SQL Server 2008 R2 column containing a string which I need
I need to split a string into two parts. The string contains words separated
I need to split a keyword string and turn it into a comma delimited
How can we handle ascii characters using sql server 2005? Which data type can
Hello I need split a String by . Have : $string = Step one
I have a string something like this. ars:a:currency (Argentina!: Pesos): i need to split
I want to insert multiple email into SQL Server table cell and before inserting
I was wondering if I have SQL Server 2008 table that was created like

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.