DROP PROCEDURE IF EXISTS DecimateLog;


DELIMITER $$

CREATE PROCEDURE DecimateLog(
    pStartDate DATETIME, 
    pPlantId	INT, 
    pMinInt		INT,
    pFluxType	VARCHAR(250)
)
BEGIN
    
    DECLARE pCounter INT DEFAULT 1;
    DECLARE pDt DATETIME DEFAULT pStartDate;
    DECLARE pMaxStep INT DEFAULT 1;
    
    WHILE pDt <= DATE_ADD(NOW(), INTERVAL -pMinInt MINUTE) DO
    		#SELECT pDt;
    		CALL DeletePlantLogrecords(pDt, pPlantId, pMinInt, pFluxType);	
      	SET pCounter = pCounter + 1;
      	SET pDt = DATE_ADD(pDt, INTERVAL pMinInt MINUTE);
    END WHILE;

END$$

DELIMITER ;