Gossamer Forum
Home : General : Databases and SQL :

delete 'out of date' rows from table

Quote Reply
delete 'out of date' rows from table
heya =)

I have a table with a TIMESTAMP in it, where i like a PROCEDURE to do a check though the table, if any of the record is older then 2weeks (14days) they shall be deleted.
I have tryed some diffence thinks, but i have still not got any luck geting something together. I'm using InterBase 6.0, and some code i have been trying so far u can see below


Have a Trigger on the table:
SET TERM ^ ;
CREATE TRIGGER SET_TIMESTAMP FOR BB_BIGGER_3WEEKS
ACTIVE BEFORE INSERT POSITION 0
as
begin
NEW.TIME_STAMP = CURRENT_DATE;
end
^

Then to remove the old record i use the command line:
DELETE FROM BB_BIGGER_3WEEKS WHERE TIME_STAMP < CURRENT_TIMESTAMP - 14;

well this dont work because now it take 14 from time or something, not date, and it allso need to know if it get below 01.11.02 (when it's pulling down the 14days) it need to start at the previous mount (31.10.02) to count down from.
So anyone know how to do this, or know if there is a funktion i can call to do it for me ?


Thx
Gandi