I'm trying to create an archiving event, and what I came up with look like this:
SET @Date = NULL;
SET @SEDOL = NULL;
CREATE EVENT IF NOT EXISTS Archive_Event
ON SCHEDULE EVERY 1 DAY
DO
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc limit 1
WHILE @date is not null
begin
begin transaction
-- Adds old line to archive
insert into daily.Archive_analytics
select * from daily.analytics where Date = @Date AND SEDOL = @SEDOL
-- Deletes old line from main table
delete from daily.analytics where Date = @Date AND SEDOL = @SEDOL
commit transaction
-- Find the next greater minimum value
SELECT @Date = Date,@SEDOL = SEDOL
from daily.analytics
where Date = (SELECT MIN(Date)
from daily.analytics
WHERE Date < date_sub(NOW(), INTERVAL 21 DAY))
order by SEDOL desc
limit 1
END WHILE
END
Searching the web this seems to be more or less correct, however my WHILE statement is getting a "Syntax Error, unexpected while_sym, expecting END_OF_INPUT or ';'" and I'm not quite sure why.
Would greatly appreciate any help.
endfor thebeginafter thewhile?