Solved

column header in alphabatical order

Posted on 2003-12-04
4
297 Views
Last Modified: 2012-06-22
How to select from a table so it displays the field names (not data) in alphabetical order?
Is there any option in Query Analyzer?

== > Select * from A order by (column header)

I have a table with more than 100 columns so sometimes it difficult to navigate to the right column easier to find if it is alphabetical.

INFORMATION_SCHEMA displays columns in alphabetical order does not display the data.
0
Comment
Question by:iqbalj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 100 total points
ID: 9877268
no automatic way of doing it...

you can generate a query to doit however....

declare @colname varchar(8000)

select @colname = @colname + column_name + ',' from information_schema.columns
 where table_name = 'yourtable'
 order by 1

declare @sqlstr varchar(8000)

set @sqlstr = 'select ' + left(@colname,datalength(@colname)-1)
    + ' from YOURTABLENAME WHERE ....'

then Print @sqlstr
or exec(@sqlstr)




0
 

Author Comment

by:iqbalj
ID: 9878450
Well, I'm hoping for some easy syntax or or some sort of configuration change....let see if anybody else has other suggestions..Thx
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 25 total points
ID: 9878745
Agree with Lowfatspread,
no easy syntax for this ...

But you can create your own ...
Use Lowfatspread's code, turn it into a stored procedure, with @table_name as an input parameter

then use

exec usp_ordered_select_from '<table name>'

isn't that an easy syntax ?
you could even add another input parameter to select only the top N records (useful for huge tables)

Just my two cents ...

Hilaire
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 100 total points
ID: 9880772
is the table normalised correctly?

have you considered normalising it...
 or at least expressing normal group by having several "subset" views defined...

the only way to get this automatically is to create the table with the columns in the order you desired....

(although i'm not clear from an ANSI/ISO SQL standard viewpoint wether column order in a
Select * case is formally defined as being in physical ddl create order )
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question