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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:00:29+00:00 2026-05-25T21:00:29+00:00

ColumnName IsOrdered Seq_ID ABC 2 2 DEF 1 1 GHI 0 NULL JKL 1

  • 0
ColumnName  IsOrdered    Seq_ID
ABC          2              2
DEF          1              1
GHI          0             NULL
JKL          1              4
MNO          1              3
PQR          0              5

I have a table (table1) in the database with above values stored in it.

Note: –

I. Is_Ordered column: 2 –> Desc; 1 –> Asc; 0 –> Default.

II. Seq_ID column: Column names ‘order by’ sequence

These values are stored in the above table by user.(i.e. on User interface). I want to produce a ‘order by’ clause from the multiple rows to a single statement with comma ‘,’ seperated (one single column).

eg: select * from Table1 order by DEF asc, ABC desc, MNO asc, JKL asc

Here I want to write a sql statement to produce just the order by statement as above shown i.e. (order by DEF asc, ABC desc, MNO asc, JKL asc)

Here you will notice that GHI column and PQR columns are not included since these two are not selected in the order by selections in the user interface.

I thank you in advance who tried to understand my question and given an appropriate solution for this.

  • 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-25T21:00:30+00:00Added an answer on May 25, 2026 at 9:00 pm

    Here you go (may need to add a CAST)

    SELECT
        'ORDER BY ' +
          SUBSTRING(
          (
          SELECT
              ',' + ColumnName + 
                   CASE IsOrdered  
                     WHEN 1 THEN 'ASC'
                     WHEN 2 THEN 'DESC'
                   END
          FROM
              MyTable
          WHERE
              IsOrdered > 0 -- why have "IsIncluded" column ?
          ORDER BY
              Seq_ID
          FOR XML PATH ('')
          )
          , 2, 7999)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried with ado.net create table columnName with unique name. as uniquename I
I currently have a table structure that looks something like this(some details omitted): ColumnName
I have a SQL statement, select ColumnName from Table And I get this result,
Guys i have stored a null value in the column of sqlite database the
I have this foreach (var columnName in columns) { writer.RenderBeginTag(HtmlTextWriterTag.A); writer.AddAttribute(href, null); writer.Write(Delete); writer.RenderEndTag();
I have the following code which returns results back from a database where columnName
I have the following table: +------------------+ | ColumnName | +------------------+ | 1 Slap |
I have a table called Transactions with the following schema: ColumnName DataType Constraints ----------
I want to Update Column of a Table where ColumnName will be DropDown.SelectedValue. Example:
When I execute the following: INSERT ALL INTO table@database_link(columnName) VALUES (columnValue) SELECT columnValue FROM

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.