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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:43:04+00:00 2026-05-23T04:43:04+00:00

While trying to execute the below query Declare @t table (id int, string varchar(1000))

  • 0

While trying to execute the below query

Declare @t table (id int, string varchar(1000))

INSERT INTO @t (id, string)
SELECT 1, 'zxzzxx,ppppbppp,trtrtr,tyyt,hgghh,fefew,rewr,rwerer' 

;WITH test (id, lft, rght, idx)
AS 
(
        SELECT t.id
                ,LEFT(t.string, CHARINDEX(', ', t.string) - 1)
                ,SUBSTRING(t.string, CHARINDEX(', ', t.string) + 2, DATALENGTH(t.string))
                ,0
        FROM @t t
        UNION ALL
        SELECT c.id
                ,CASE WHEN CHARINDEX(', ', c.rght) = 0 THEN c.rght ELSE LEFT(c.rght, CHARINDEX(', ', c.rght) - 1) END
                ,CASE WHEN CHARINDEX(', ', c.rght) > 0 THEN SUBSTRING(c.rght, CHARINDEX(', ', c.rght) + 2, DATALENGTH(c.rght)) 
                        ELSE '' END
                ,idx + 1
        FROM test c 
        WHERE DATALENGTH(c.rght) > 0
)

select id, lft from test 

I am getting the below error

Msg 537, Level 16, State 2, Line 8
Invalid length parameter passed to the LEFT or SUBSTRING function.

but the same works for SELECT 1, ‘the, quick, brown, fox, jumped, over, the, lazy, dog’

Please help

  • 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-23T04:43:05+00:00Added an answer on May 23, 2026 at 4:43 am

    It seems to be a space missing between your words.

    You are currently looking for charindex of ', ' not ','.

    And the string does not have any match of ', '.

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

Sidebar

Related Questions

I hit this error while my web application was trying to execute a SELECT
While trying to execute the following lines only the last two statements are displayed(Here
Hello I have a very large SQL script and while trying to execute it
While trying to use LINQ to SQL I encountered several problems. I have table
While trying to integrate Yahoo Media Player into my own website, I want to
I'm trying to execute a firmware upgrade while my programming is running in inittab.
Just started ROR Lynda Tutorial, Error while trying to execute the rails server in
i'm trying to insert multiple data using a query, i've tried the implode function,
I am trying to execute the below code from a console app. ConfigurationSection aggregatedFileSection
I'm trying to insert some files into a Postgres database. Since lots of duplication

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.