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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:26:25+00:00 2026-06-04T02:26:25+00:00

I have a query where I’m selecting more than 15 things, and thus getting

  • 0

I have a query where I’m selecting more than 15 things, and thus getting (more than) 15 columns in my results. Some of the things I’ve selected are big CASE statements. T-SQL of course displays your result in the order than you list things in the SELECT statement.

Is there a way to have the result columns displayed in a different order to help with my review of them, without

a) re-ordering how they were selected (because I’ll need to do this every time I want to compare two other columns side-by-side)

i.e. Don’t want to change: SELECT a,b,c,d,e,f to SELECT f,d,a,b,c,e
since a-f can each be 5-10 lines of code

b) drag-n-drop column in the results next to each other, because if I want column 2 to be next to column 9 and column 14, and all three to be at the end of the result table, then that’d a lot of dragging to do.

c) knowing the column number of what was selected as opposed to the column name

What I’m looking for is something that resembles:

Select
    vi.Name
   ,vi.Height
   ,vi.Power
   ,case when tt.losses < 3
         then 'Y'
         else 'N'
    end as MasteryKen
   ,tt.blahnum
   ,vi.blahtext
   ,vi.blahdate
   ,vi.blahcalc
   ,tt.blahflag
   ,vi.blahflag
   ,vi.blahcompare

From SenshiVitalInfo vi 
Join TatakauTable tt 
  on vi.namecd=tt.namecd

OrderOutputResults by tt.blahflag, vi.blahflag, *

Does a function to do the last line exist in T-SQL (SQL Server 2008)?

  • 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-04T02:26:27+00:00Added an answer on June 4, 2026 at 2:26 am

    There is no functionality in TSQL to “move” the columns around, other than editing the SELECT list order, this is the best you can do:

    SELECT
        d.Name
       ,d.Height
       ,d.Power
       ,d.MasteryKen   --<<can now move around single lines
       ,d.blahnum
       ,d.blahtext
       ,d.blahdate
       ,d.blahcalc
       ,d.blahflag
       ,d.blahflag
       ,d.blahcompare
    FROM (Select
              vi.Name
             ,vi.Height
             ,vi.Power
             ,case when tt.losses < 3
                   then 'Y'
                   else 'N'
              end as MasteryKen
             ,tt.blahnum
             ,vi.blahtext
             ,vi.blahdate
             ,vi.blahcalc
             ,tt.blahflag
             ,vi.blahflag
             ,vi.blahcompare
    
          From SenshiVitalInfo vi 
          Join TatakauTable tt 
            on vi.namecd=tt.namecd
         ) d
    --ORDER BY ....
    

    You can wrap your existing query inside a derived table, where you can then move the single line columns names all you want. Just make sure that any ORDER BY is moved out of the derived table.

    If You are using SSMS, you can view your result set in “results to grid” mode and just drag and drop the column headings to slide the columns around.

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

Sidebar

Related Questions

I have query table copyQuery which has Soil Condition has one of the columns,
I've noticed that some sites (including the old http://careers.stackoverflow.com 1.0) have query strings that
I have query that gives back results like this: Client1 Product1 $500 Client1 Product2
I'm looking for more information how to modify Postgres 9..0 query plan. I have
I have query regarding selected key in JavaScript. I am developing a sql query
I have very big problem in my SQL query and i don't know how
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I am using in C# MYsql .I have query that works if I run
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

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.