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

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

akpaga
Constraint Violating Yak Guru

USA
313 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 order..is that doable?

Thank you

lazerath
Constraint Violating Yak Guru

USA
342 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)

MJ
Go to Top of Page

akpaga
Constraint Violating Yak Guru

USA
313 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  
 New 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.08 seconds. Powered By: Snitz Forums 2000