Solved

Exclusive Query?

Posted on 2008-10-11
2
207 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

772 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

9 Experts available now in Live!

Get 1:1 Help Now