Solved

T-SQL Exclusion Question

Posted on 2013-01-25
9
234 Views
Last Modified: 2013-01-26
Hi,
 have an idea on this but I am not sure.

I have a table with a 2 column key
ImageTable

KEY:
-  ArticleID integer
-  ImageName  varchar(50)


Data1 varchar(50)
Data2 varachar(50)
etc

I want an SQL (SQL Server 2005) that will select all rows of the table except for 1 row where
ArticleID = 38
ImageName = 'my image'

I have an idea but wanted to see what someone else came up with.

Thanks in advance,
hefterr
0
Comment
Question by:hefterr
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 38818627
Is this what you want?  Thats what i understood from your question.

Select * from Articles where ArticleID <> 38 AND ImageName <> 'my image'

Open in new window


Hope this helps
0
 
LVL 11

Expert Comment

by:Simone B
ID: 38818628
SELECT * FROM ImageTable
WHERE ArticleID <> 38 AND ImageName <> 'my image'
0
 
LVL 13

Accepted Solution

by:
Philip Pinnell earned 500 total points
ID: 38818640
SELECT * FROM ImageTable
WHERE Not (ArticleID = 38 AND ImageName = 'my image' )
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Expert Comment

by:Jim Horn
ID: 38818649
The above experts are correct.  Quick question though:

>except for 1 row where
Does the '1 row' have any significance, as in are there multiple rows with 38 and 'my image' but the requirement is to delete only one?
0
 
LVL 1

Author Comment

by:hefterr
ID: 38818672
To all,
I think you solutions will not also select the following rows:

ArticleID 38
Image Name = 'image1'

ArticleID = 38
ImageName = 'image2'

etc.   Right?
0
 
LVL 11

Expert Comment

by:Simone B
ID: 38818710
Mine and binaryevo's solutions are incorrect for that reason. andycrofts solution is the best one to do what you're looking for. It will filter out ONLY the row where ID = 38 and ImageName = 'my image'
0
 
LVL 1

Author Comment

by:hefterr
ID: 38818744
I also think andycrofys is the correct solution. I'll try it out.

Not sure which is better, but I think I just read :

Select * from ImageTable
Except
Select * from ImageTable where ArticleID = 38 AND ImageName = 'my image'

Thoughts?
0
 
LVL 1

Author Closing Comment

by:hefterr
ID: 38819393
Thanks.  Didn't no about the "NOT".

I think my "EXCEPT" would also work?
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 38822705
thanks
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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…

730 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