Solved

column header in alphabatical order

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

757 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

23 Experts available now in Live!

Get 1:1 Help Now