CREATE TRIGGER tr BEFORE UPDATE ON batch_dat_trans FOR EACH ROW BEGIN DECLARE @result_position int; DECLARE @result_all int; DECLARE @proud double; DECLARE @date1 DATE; DECLARE @cust varchar(100); SET @result_position = 1; DELETE FROM temp; SELECT COUNT(@Batch_Date) INTO @result_all FROM batch_dat_trans WHERE Batch_date BETWEEN DATE_SUB(NOW(), INTERVAL 45 DAY) AND NOW() ; lab: LOOP SELECT Batch_Date,Customer_Code,Production_Qty INTO @date1,@cust,@proud FROM batch_dat_trans WHERE Batch_date BETWEEN DATE_SUB(NOW(), INTERVAL 25 DAY) AND NOW() LIMIT @result_position,1 ; INSERT INTO temp (Batch_Date,Customer_Code,Production_Qty) VALUES(@date1,@cust,@proud); SET @result_position = @result_position + 1; if @result_position > @result_all then LEAVE lab; end if; END LOOP; END
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)