Solved

Exclusive Query?

Posted on 2008-10-11
2
208 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now