Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 help with not exists

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-12 : 07:49:09
Alex writes "I have 2 tables, Agents table and a Sales table both with a common field, AgentID, i'm trying to create a query that searches for those Agents who have not made any sales between 2 dates, i would figure the code below to work, BUT i get an empty response, can you help?

Select * FROM AgentsQ
WHERE NOT EXISTS (
SELECT *
FROM SalesQ
WHERE ClosingDate BETWEEN #8/1/2004# AND #8/1/2005#) Order By
AgentOfficeID, Tier"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-08-12 : 07:52:09
You did not corellate the subquery to the outer query:

Select * FROM AgentsQ A
WHERE NOT EXISTS (SELECT * FROM SalesQ B WHERE ClosingDate BETWEEN '8/1/2004' AND '8/1/2005' AND B.AgentID=A.AgentID)
Order By AgentOfficeID, Tier"
Go to Top of Page
   

- Advertisement -