Solved

SQL NOT IN

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

746 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

11 Experts available now in Live!

Get 1:1 Help Now