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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can you use column order value in select statement

Author  Topic 

Conjurer
Starting Member

30 Posts

Posted - 2005-11-06 : 01:42:56
Is there a shortcut to spelling out column names when you are doing a select statement?

For instance could you write Select 1, 5, 6 from table where whatever...

I tried this but didn't get any results so if you can I must be using wrong syntax.

Thanks
!

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-06 : 02:36:09
First of all you cant specify ORDINAL POSITION of the column in the select statement.. it can be specify in the oder by ..

but its always better to use the COLUMN NAME In the select statement.. for the better readablity ..

Complicated things can be done by simple thinking
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-06 : 08:17:07
You can generate it if you have a single table you want to get he columns from

select name + ' ,' from syscolumns where id = object_id('mytbl')
order by
case when colid = 1 then 1
when colid = 5 then 2
when colid = 6 then 3
else 999
end


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -