?
Solved

column header in alphabatical order

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

771 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