This would be easy with the SQL EXCEPT command, but I don't think that exists in SQL 2000. In this case, you would need to do a self join using LEFT JOIN and only return the records where the joined-to values are NULL.
That's as clear as mud, I know -- so let me work on a solution.
[edit]
I didn't try this out, but it should work or be close:
Code:
Select A.*, isNull(B.OldFlag, '(new)')
From myTable A
Left Join (
Select EQ, 'Old' as OldFlag
from myTable
Where MonthYr <= '2009-11-01'
) B
On (A.EQ = B.EQ)
Where A.MonthYr = '2009-12-01'
And B.OldFlag is null
Note that I just hard coded the dates in, not optimal. If you can, use a parameter for the starting date.
Code:
Select A.*, isNull(B.OldFlag, '(new)')
From myTable A
Left Join (
Select EQ, 'Old' as OldFlag
from myTable
Where MonthYr <= dateadd(m, -1, @rptMonth)
) B
On (A.EQ = B.EQ)
Where A.MonthYr = @rptMonth
And B.OldFlag is null
and set @rptMonth to something like '2009-12-01' for December.
[/edit]
Bookmarks