Solved

column header in alphabatical order

Posted on 2003-12-04
4
294 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now