Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I just can't get it.I need a list of records that don't have a matching record exactly 1 year later which are joined on 'Number'.i am also filtering on displaying only the records in the following date range: 7/1/2005 - 6/30/2006 who don't have a matching record 1 year later, so the 7135 record would not show up, even though it doesn't have a matching record a year later (2007-07-01). id number name Date2537 DAN1 Dan's Tutoring 2005-07-01 7135 DAN1 Dan's Tutoring 2006-07-01 2112 SS2211 SuperSaver 2005-09-013311 Upper3 Upper III 2005-09-076336 Lowest LowestClass 2006-08-01So what should be returned is records 2112 & 3311 This is my failed attempt to do so:SELECT DISTINCT a.ID, a.NUMber, a.NAME, a.DaTe FROM CLASS aLEFT OUTER JOIN CLASS b ON a.NUMber = b.NUMBERAND a.DATE != DATEADD(YEAR, -1, b.DATE)I am in great need of this and thanks a lot to any contributors
blindman
Master Smack Fu Yak Hacker
2365 Posts
Posted - 2006-01-23 : 11:03:56
Filter this however you want:
SELECT DISTINCT a.ID, a.NUMber, a.NAME, a.DaTe FROM CLASS a LEFT OUTER JOIN CLASS b ON a.NUMber = b.NUMBER AND a.DATE = DATEADD(YEAR, -1, b.DATE)WHERE b.NUMBER is null