SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 One to Many Date Filter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bholmstrom
Yak Posting Veteran

USA
75 Posts

Posted - 03/01/2013 :  14:38:19  Show Profile  Reply with Quote
Good afternoon. I have a query that needs to filter out any records that do not have a modifydate entry after 1/1/2009

Here are the code:

select a.account,b.modifydate
from sql1.sysdba.Account A
left outer join sql1.sysdba.Opportunity B ON b.accountid = b.accountid
where b.modifydate < '2009-01-01 00:00:00.00'

This code works except in my test data one record has 168 entries in the opportunity table, and some are greater that the above date. What this means is that record "a" should NOT be on the list/output.

Sorry for the long explanation, any ideas ?

Thanks




Bryan Holmstrom

James K
Flowing Fount of Yak Knowledge

3741 Posts

Posted - 03/01/2013 :  16:37:18  Show Profile  Reply with Quote
SELECT
	a.account,b.modifydate
FROM
	sql1.sysdba.Account A
	inner join sql1.sysdba.Opportunity B
		ON b.accountid = b.accountid 
WHERE NOT EXISTS
(
	SELECT * FROM sql1.sysdba.Opportunity x
	WHERE x.modifydate >= '20090101'
	AND x.accountid = b.accountid
);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000