Solved

Exclusive Query?

Posted on 2008-10-11
2
210 Views
Last Modified: 2012-05-05
Experts,

Let's say I have a table with 10 fields, and I want to SELECT all of them but one.  Can I do this without listing the 9 I want, but telling SQL I want all fields but the one I don't want?
0
Comment
Question by:NigelRocks
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 22693743
NigelRocks said:
>>Can I do this without listing the 9 I want, but telling SQL I want all fields but the one I don't want?

No.  You can either use * to say "get all the columns", or you have to specify the columns you want.
There is no other way.
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 250 total points
ID: 22693754
Not possible in a normal query.  One thought is to use a dynamic query, but much easier just to use some of the tricks to get SQL to populate the columns for you and then delete the one you want.  There are a couple mentioned in the linked article/discussion on this topic below, but here is another trick:

In SQL Management Studio, if you open a table there is a SQL query associated like:
SELECT * FROM TableName

If you click at end of Query and then add an enter or space, and then click on the verify query/syntax button -- SQL Management Studio will change query to be:
SELECT co1, col2, col3, col4, ... FROM TableName

Hope this helps.

http://weblogs.sqlteam.com/jeffs/archive/2007/07/26/60271.aspx
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

786 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