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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:17:56+00:00 2026-06-18T08:17:56+00:00

i have a trouble when i want to create a csv From Table ..

  • 0

i have a trouble when i want to create a csv From Table ..

here it’s my table sample…

ID  HEADER_row  Value_row
1   A             100
2   B             200
3   C             300
4   D             400
5   E             500
6   A             600
7   B             700
8   C             800
9   D             900
10  E             1000

and its the csv data model that i want to create, check this out guys:

A   B   C   D   E   A   B   C   D   E
100 200 300 400 500 600 700 800 900 1000

and

A   B   C   D   E
1OO 2OO 3OO 4OO 5OO
600 700 800 900 1000

I Already try this for my first model problem…

SELECT STUFF(
(SELECT ',' + s.ElementName
FROM tableName s
FOR XML PATH('')),1,1,'') 

UNION ALL

SELECT STUFF(
(SELECT ',' + s.Value
FROM tableName s
FOR XML PATH('')),1,1,'') 

but it give me the result like this:

A   B   C   D   E   A   B   C   D   E
100 200 300 400 500 600 700 800 900 1000

now i want to get the other result like this

 A  B   C   D   E
    1OO 2OO 3OO 4OO 5OO
    600 700 800 900 1000

what kind of query i should use on my problem beside using pivot?

  • 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-18T08:17:57+00:00Added an answer on June 18, 2026 at 8:17 am

    To split this data into separate rows you are going to include the use of row_number() in the second query that gets the Value_row:

    By applying the row_number() you can partition the data by the Header_row value to assign two separate number:

    select Value_row,
      row_number() over(partition by header_row order by id) rn
    from yourtable
    

    See SQL Fiddle with Demo. This query gives the result:

    | VALUE_ROW | RN |
    ------------------
    |       100 |  1 |
    |       600 |  2 |
    |       200 |  1 |
    |       700 |  2 |
    |       300 |  1 |
    |       800 |  2 |
    |       400 |  1 |
    |       900 |  2 |
    |       500 |  1 |
    |      1000 |  2 |
    

    Then you incorporate this into your existing query so the code will be:

    SELECT STUFF(
                (SELECT ',' + s.HEADER_row
                FROM yourtable s
                FOR XML PATH('')),1,1,'') 
    UNION ALL
    SELECT DISTINCT 
      STUFF(
                (SELECT ',' + cast(Value_row as varchar(50))
                from
                (
                  select Value_row,
                    row_number() over(partition by header_row order by id) rn
                  from yourtable
                ) src      
                where r.rn = src.rn
                FOR XML PATH('')),1,1,'')
    FROM
    (
      select Value_row,
        row_number() over(partition by header_row order by id) rn
      from yourtable
    )r ;
    

    See SQL Fiddle with Demo

    This gives the result:

    |                 LIST |
    ------------------------
    |  A,B,C,D,E,A,B,C,D,E |
    |  100,200,300,400,500 |
    | 600,700,800,900,1000 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble here, do you know Yahoo! News? I want to create
I want to create an 1,k cell of m,m matrices. I have some trouble
I want to create hiscore list, but I have trouble doing it. This is
I have trouble doing this... You may want to get the same result as
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
I'm having trouble getting my links the way I want them. Currently, I have
i'v got a trouble, i want to use Ckeditor with my project, i have
right guys im having trouble with one. what i want to do is have
I'm having some trouble figuring this out. I have the following CSV string hello
I want to create games for Iphone/Ipod touch. Unfortunately I don't have a lot

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.