Solved

SQL NOT IN

Posted on 2012-03-23
1
222 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
[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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

726 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