Using SQL Server 2008 R2: I have a table called Data
. I want delete all rows in which activity A and activity B both occur in the same date range for the same account (as represented below by field "key"), as together they constitute a "wash".
If I code:
Delete Data D1
from Data1
inner join Data D2
on D1.key = D2.key
and D1.Activity = 'A'
and D2.Activity = 'B'
and D1.TranDate < EndDateRange
and D1.TranDate >= BeginDateRange
and D2.TranDate < EndDateRange
and D2.TranDate >= BeginDateRange
I can delete the row with activity 'A' from the table. How can I also delete activity 'B'? Can I do this in the same query? Once row A is deleted, the account no longer shows a wash condition.