The following is my code so far and the select query is what I would like to delete from the Events table.
declare @maxsnapevent table (sita varchar(10), snap date)
insert into @maxsnapevent
select sita, max(snapshot_date) from ukrmc.dbo.strategy group by sita
--select * from @maxsnapevent
--need to delete everything that the following code gives
select events.sita, events.date, events.event from ukrmc.dbo.events events
join @maxsnapevent max on max.sita = events.sita
where date >= max.snap and events.sita != 'lcypd' and events.sita != 'lonza'
example data from the strategy table:
date sita Event Snapshot_date
2018-01-01 London Bank Holiday 2017-12-31
2018-01-02 London 2017-12-31
2018-01-03 London 2017-12-31
2018-01-04 London Concert 2017-12-31
2018-01-02 London 2018-01-01
2018-01-03 London 2018-01-01
2018-01-04 London Concert 2018-01-01
2018-01-01 Bham Bank Holiday 2017-12-31
2018-01-02 Bham 2017-12-31
2018-01-03 Bham 2017-12-31
2018-01-04 Bham 2017-12-31
2018-01-02 Bham 2018-01-01
2018-01-03 Bham Charity 2018-01-01
2018-01-04 Bham 2018-01-01
example data from the events table:
date sita Event
2018-01-01 London Bank Holiday
2018-01-02 London
2018-01-03 London
2018-01-04 London Concert
2018-01-01 Bham Bank Holiday
2018-01-02 Bham
2018-01-03 Bham
2018-01-04 Bham Concert
As you can see each snapshot has several sitas with several dates.