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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:17:37+00:00 2026-06-08T00:17:37+00:00

I need to split a nvarchar(100) column into three nvarchar(28) columns without a known

  • 0

I need to split a nvarchar(100) column into three nvarchar(28) columns without a known delimiter and without breaking mid-word. I am thinking that I would need to find the space that is near the 28th character, measure length and position of the word just before that space and decide weather the delimiter should be before or after that word. Then, again for the 3rd column.
From:

Col
-------------------------------------------------------------------------------------
Royal Mission Open Hutch with 4-Arch Doors, Plain Glass (with Glass Shelves Standard)

To:

Col1                      Col2                      Col3
------------------------  ------------------------- --------------------------
Royal Mission Open Hutch  4-Arch Doors, Plain Glass (with Glass Shelves Standa

Any Ideas?
Thanks nab

I am using SQL 2008

  • 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-08T00:17:39+00:00Added an answer on June 8, 2026 at 12:17 am

    Using CROSS APPLYs, you could try something like this:

    WITH data (col) AS (
      SELECT CAST('Royal Mission Open Hutch with 4-Arch Doors, Plain Glass (with Glass Shelves Standard)' AS nvarchar(100))
    )
    SELECT
      col1, col2, col3
    FROM data
    CROSS APPLY (
      SELECT
        NULLIF(30 - CHARINDEX(' ', REVERSE(LEFT(col, 29))), 0)
    ) AS x1 (first_space_pos)
    CROSS APPLY (
      SELECT
        LEFT(col, ISNULL(first_space_pos, 28)),
        LTRIM(NULLIF(SUBSTRING(col, ISNULL(first_space_pos, 29), 999), ''))
    ) AS x2 (col1, col23)
    CROSS APPLY (
      SELECT
        NULLIF(30 - CHARINDEX(' ', REVERSE(LEFT(col23, 29))), 0)
    ) AS x3 (second_space_pos)
    CROSS APPLY (
      SELECT
        LEFT(col23, ISNULL(second_space_pos, 28)),
        LTRIM(NULLIF(SUBSTRING(col23, ISNULL(second_space_pos, 29), 28), ''))
    ) AS x4 (col2, col3)
    ;
    

    The first CROSS APPLY searches for the last space in the first 29 characters of the big column, and the second one uses the found position to produce the first smaller column, col1 and return the rest of the string as col23.

    The next two CROSS APPLYs do perform the same manipulations on col23, thus producing col2 and col3. The only difference is, the last CROSS APPLY puts into col3 at most 28 characters rather than all the remaining ones.

    The hardcoded values like 28, 29 and 30 could be parametrised, but I’ll leave that part of the job to you.

    You can try this query at SQL Fiddle.

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

Sidebar

Related Questions

I need to split an flv file into chunks of the known size on
I need to split a file into multiple files without compression. I found this
I need to split a string into an array on word boundaries (whitespace) while
I need to split a string from one table into two columns in another
I need to split a keyword string and turn it into a comma delimited
I need to split my string input into an array at the commas. Is
I need to split a string into chunks of 2,2,3,3 characters and was able
I need to split a string into two parts. The string contains words separated
I need to split string with delimiter of \n when I use this code:
I need to split long string into a array with following constrains: The input

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.