Solved

Exclusive Query?

Posted on 2008-10-11
2
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 60

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

707 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