Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Order columns by column headers when dispalyed?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

331 Posts

Posted - 10/09/2012 :  18:07:20  Show Profile  Reply with Quote
Hi friends,

I have a table customer with following columns A,B,C
all jumbled up

So when i use the query select * from Customer
The results show up as this

B A C but i want them to be displayed in that doable?

Thank you

Constraint Violating Yak Guru

343 Posts

Posted - 10/09/2012 :  18:33:12  Show Profile  Reply with Quote
Just do this:

SELECT A,B,C from Customer

In fact, you should avoid SELECT * in almost all production level code. The one case where it is acceptable is with EXISTS.
Go to Top of Page

Mike Jackson
Starting Member

37 Posts

Posted - 10/10/2012 :  08:52:41  Show Profile  Reply with Quote
If you have a bunch of columns you could do this....

declare @table as varchar(50)
set @table='YourTable'
declare @test as varchar(5000)
select @test= COALESCE(@test + ', ', '') + [Name]
from sys.columns
where object_id like
select Object_id
from sys.tables
where name=@table

select @test= 'Select ' + @test + ' from ' + @table

print @test

exec (@test)

Go to Top of Page

Constraint Violating Yak Guru

331 Posts

Posted - 10/11/2012 :  11:34:32  Show Profile  Reply with Quote
Thank you lazerath and mike..Really appreciate it..
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000