[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

column header in alphabatical order

Posted on 2003-12-04
4
Medium Priority
?
303 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 300 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 75 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 300 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

Technology Partners: 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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

650 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