DELIMITER //

CREATE OR REPLACE PROCEDURE compareAllMeterReads (IN starting_date datetime, IN ending_date_limit datetime)

BEGIN

	/*This proc will take a starting and ending date range. It will then call compareMeterReads
	for each date that falls within the range. A function getAvgToDate will be called by
	CompareMeterReads. So there are 2 procs and 1 function working together to get date and
	volume data for each machine in the desired date range.*/

	DECLARE audit_date DATETIME;
	
	SET audit_date = starting_date;
	
		
	WHILE (audit_date < ending_date_limit) DO
		CALL compareMeterReads(audit_date);
				
		SET audit_date = DATE_ADD(audit_date, INTERVAL 1 DAY);
	
	END WHILE;

END //

DELIMITER ;