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 2005 Forums
 Transact-SQL (2005)
 Joining tables

Author  Topic 

arch259
Starting Member

1 Post

Posted - 2010-07-21 : 09:51:17
Tab1
ID date
1 1/1/2007
1 1/5/2007
1 1/15/2007
1 1/28/2007
1 1/30/2007
2 5/4/2007
3 6/7/2007
4 5/5/2007

Tab2
ID date
1 12/12/2006
1 1/5/2007
1 1/11/2007
1 2/10/2007
2 3/5/2007
2 4/5/2007
3 3/26/2007
3 3/31/2007

Output table
ID date
1 12/12/2006
1 2/10/2007
1 2/10/2007
2 3/5/2007
2 4/5/2007
3 3/26/2007
3 3/31/2007

I want all the records from table 2 where for each ID in table 2, tab2.date does not fall within +-5 days of any in table 1 for that ID.

Thanks

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2010-07-21 : 10:04:20
So what have you tried so far?

A clue for you:

on id = id
and (t1.date > dateadd(dd,5,t2.date) OR t1.date < dateadd(dd,-5,t2.date))

Go to Top of Page
   

- Advertisement -