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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:29:01+00:00 2026-05-14T14:29:01+00:00

declare @mydata nvarchar(4000) set @mydata = ’36|0, 77|5, 132|61′ I have this data that

  • 0
declare @mydata nvarchar(4000)    

set @mydata =  '36|0, 77|5, 132|61'

I have this data that I need to get into a table. So for Row1 columnA would be 36 and columnB would be 0. For Row2 columnA would be 77 and columnB would be 5 etc.

What is the best way to do this?

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-05-14T14:29:02+00:00Added an answer on May 14, 2026 at 2:29 pm

    You need a split table-valued-function. There’s plenty of examples on the web, e.g. http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

    CREATE FUNCTION dbo.Split
    (
        @RowData nvarchar(2000),
        @SplitOn nvarchar(5)
    )  
    RETURNS @RtnValue table 
    (
        Id int identity(1,1),
        Data nvarchar(100)
    ) 
    AS  
    BEGIN 
        Declare @Cnt int
        Set @Cnt = 1
    
        While (Charindex(@SplitOn,@RowData)>0)
        Begin
            Insert Into @RtnValue (data)
            Select 
                Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
    
            Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
            Set @Cnt = @Cnt + 1
        End
    
        Insert Into @RtnValue (data)
        Select Data = ltrim(rtrim(@RowData))
    
        Return
    END
    go
    
    declare @mydata nvarchar(4000)     
    set @mydata =  '36|0, 77|5, 132|61' 
    
    select
        rowid, [1] as col1, [2] as col2
    from
    (
        select
            Row.Id as rowid, Col.Id as colid, Col.Data
        from dbo.Split(@mydata, ',') as Row
            cross apply dbo.Split(Row.Data, '|') as Col
    ) d
    pivot
    (
        min(d.data)
        for d.colid in ([1], [2])
    ) pd
    

    I just picked the first split function I found. I don’t thnk it’s the best one but it works for this eample.

    Ths outputs:

    rowi     col1     col2
    1   36  0
    2   77  5
    3   132 61
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
I have a very generic set of three tables that store all of my
I have a stored procedure that accepts a date input that is later set
Okay, basically, I have formed a mySQL query which returns a data set all
In the following code block, why do I need to declare myData in the
Suppose I declare a structured Javascript variable like this: var mydata = {'list':[ {'fname':'george','lname':'washington'}
I have a class for my data, MyData , and I'm accessing it in
I have a sql query with 50 parameters, such as this one. DECLARE @p0
I have a data table like this: Group ID M0 M1 ... M20 ------------------------------------
How to get the json array from the URL.I declare the mydata as a

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.