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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how to get all columns except one

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-12-11 : 17:39:03
Hi friends
is it possible to get all columns except one in select list ?
i know that i can do following to achieve that but there are quite a few columns in that table and dont want to type in all of those columns?

select col1,col2 from mytable

i mean something like below can be done ?
select mytable.* except col3 from mytable

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-11 : 17:44:19
You should always explicit type all column names in the select list.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-12-11 : 17:48:03
Yup, I agree with Peso.

If you want to achieve what you're describing then you will be headed down the dynamic sql path.



Nathan Skerl
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-12-11 : 18:01:50
Are you just too lazy to type up the columns? If so, you can generate the columns easily in Query Analyzer using the object browser

Tara Kizer
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-12-11 : 18:02:55
Here's some helper code:

SELECT Column_Name + ', ' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='myTable' AND COLUMN_NAME<>'notTheColumnIWant'

Change the table and unwanted column name as needed, and copy and paste the results into your code.
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-12-12 : 20:49:14
Thank you very much guys.
in Visual foxpro there is a "Except Fields" clause so just wondered if there is something like that available in sql!

Cheers
Go to Top of Page
   

- Advertisement -