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

The Archive Base Latest Questions

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

Hi I have an input as ID data 1 hello 2 sql The desired

  • 0

Hi I have an input as

ID  data
1   hello
2   sql

The desired output being

ID  RowID  Chars
1    1     H
1    2     e
1    3     l
1    4     l
1    5     o
2    1     s
2    2     q
2    3     l

My approach so far being

Declare @t table(ID  INT IDENTITY , data varchar(max))
Insert into @t Select 'hello' union all select 'sql'
--Select * from @t
;With CteMaxlen As(
Select MaxLength = max(len(data)) from @t)
, Num_Cte AS
(     
      SELECT 1 AS rn
      UNION ALL
      SELECT rn +1 AS rn 
      FROM Num_Cte 
      WHERE rn <(select MaxLength from CteMaxlen)
)
-- Shred into individual characters
, Get_Individual_Chars_Cte AS
( 
      SELECT  
            ID
            ,Row_ID =ROW_NUMBER() Over(PARTITION by ID Order by ID)
            ,chars               
      FROM @t,Num_Cte
      CROSS APPLY( SELECT SUBSTRING((select data from  @t),rn,1)  AS chars) SplittedChars       
)

Select * from Get_Individual_Chars_Cte 

The query is not working at all with an exception being

Msg 512, Level 16, State 1, Line 4
Subquery returned more than 1 value.
This is not permitted when the
subquery follows =, !=, <, <= , >, >=
or when the subquery is used as an
expression.

Edit :

I found my answer

;with Get_Individual_Chars_Cte AS
( 
   SELECT 
        ID,
        Row_ID =ROW_NUMBER() Over(PARTITION by ID Order by ID) 
        ,SUBSTRING(Data,Number,1) AS [Char]--,

FROM @t  
INNER JOIN master.dbo.spt_values ON
 Number BETWEEN 1 AND LEN(Data)
 AND type='P'

)

Select * from Get_Individual_Chars_Cte 

Help needed

  • 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:55:14+00:00Added an answer on May 23, 2026 at 4:55 am
    ;with cte as
    (
      select ID,
             substring(data, 1, 1) as Chars,
             stuff(data, 1, 1, '') as data,
             1 as RowID
      from @t
      union all
      select ID,
             substring(data, 1, 1) as Chars,
             stuff(data, 1, 1, '') as data,
             RowID + 1 as RowID
      from cte
      where len(data) > 0
    )
    select ID, RowID, Chars
    from cte
    order by ID, RowID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
I have the following input data in String: Hello #this# is #sample# text. It
We have some input data that sometimes appears with &nbsp characters on the end.
I have an input edit field where the user can enter data. I want
In my scenario, I have a program that analyzes data input files and produces
I have a streaming input which has repeated values. I can use any data
I have some data (which users input using WYSIWYG editor). I have created a
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
Hello i have an html form and i'm posting data but i'm unable to
Hello I have the following piece of code and it won't post the data

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.