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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:30:20+00:00 2026-06-06T21:30:20+00:00

I am getting data in 6 columns. How can I sort these columns into

  • 0

I am getting data in 6 columns. How can I sort these columns into their values and store them to either new column or the same column.

Input
ID  N1 N2 N3 N4 N5 N6
1   6  4  5  3  1  2
2   42 43 46 45 48 47

Desired Output
ID  N1 N2 N3 N4 N5 N6  S1 S2 S3 S4 S5 S6
1   6  4  5  3  1  2   1  2  3  4  5  6
2   42 43 46 45 48 47  42 43 45 46 47 48 
  • 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-06T21:30:21+00:00Added an answer on June 6, 2026 at 9:30 pm
    select T.ID, T.N1, T.N2, T.N3, T.N4, T.N5, T.N6, 
           N.X.value('N[1]', 'int') as S1,
           N.X.value('N[2]', 'int') as S2,
           N.X.value('N[3]', 'int') as S3,
           N.X.value('N[4]', 'int') as S4,
           N.X.value('N[5]', 'int') as S5,
           N.X.value('N[6]', 'int') as S6
    from YourTable as T
    cross apply
      (
        select N
        from (values (N1),(N2),(N3),(N4),(N5),(N6)) as N(N)
        order by N.N
        for xml path(''), type
      ) as N(X)
    

    SE-Data

    Same thing but using pivot instead of XML.

    select P.ID, P.N1, P.N2, P.N3, P.N4, P.N5, P.N6,
           P.[1] as S1,
           P.[2] as S2,
           P.[3] as S3,
           P.[4] as S4,
           P.[5] as S5,
           P.[6] as S6
    from
      (
        select T.ID, T.N1, T.N2, T.N3, T.N4, T.N5, T.N6, N.N, N.rn
        from YourTable as T
        cross apply
          (
            select N,
                   row_number() over(order by N.N) as rn
            from (values (N1),(N2),(N3),(N4),(N5),(N6)) as N(N)
          ) N
      ) as T
    pivot (min(T.N) for T.rn in ([1],[2],[3],[4],[5],[6])) as P
    

    SE-Data

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

Sidebar

Related Questions

how can i getting data from listbox in second form named listform while i
I am getting data nightly from a web service that stores their fields in
Whole afternoon I am struggling with the getting data from associations. I have these
I have a data frame with 22239 rows & 200 columns. The first column
How can i get the the JqGrid column to sort as per date time,
In my code I'm getting data (three columns) from a sql db and I
Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
I am getting data from iphone using php but when i insert post data
I am getting data from server it gives in response a NSString which hase
The problem is getting data in my dataGridView from my webservice. When i invoke

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.