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
Solved

SQL NOT IN

Posted on 2012-03-23
1
221 Views
Last Modified: 2012-06-22
I need to SELECT claims from b_claim table based on data  I have data for the epccc table.


select b_claim.epcccId, * from b_claim INNER JOIN epccc ON epcccId =epccc.Id where b_claim.agencyId = 18 and epcccEpId = 25363
and epcccId  NOT IN (select id from epccc where epcccEpId = 25363
and agencyId = 18 and coalesce(epcccCccId,0) not in (-0,408))


The above works good when

(select id from epccc where epcccEpId = 25363
and agencyId = 18 and coalesce(epcccCccId,0) not in (-0,408))

returns at least one row but when it returns nothing the whole query returns everything.  

I would like it if the NOT IN portion returns nothing then I want the whole query to return nothing.  How do I do this?
0
Comment
Question by:huerita37
1 Comment
 
LVL 6

Accepted Solution

by:
ingriT earned 500 total points
ID: 37757413
Not the prettiest way;

select b_claim.epcccId, * from b_claim INNER JOIN epccc ON epcccId =epccc.Id where b_claim.agencyId = 18 and epcccEpId = 25363
and epcccId  NOT IN (select id from epccc where epcccEpId = 25363
and agencyId = 18 and coalesce(epcccCccId,0) not in (-0,408))
AND NOT ((select Count(id) from epccc where epcccEpId = 25363
and agencyId = 18 and coalesce(epcccCccId,0) not in (-0,408)) = 0)
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

840 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