The stored proc is set up so the user can call it using any dates. I want to be able to restrict the date passed to two months.
Right now when the user calls the report without any dates selected, the report server crashes because there is too much data. I want to be able to either limit the rows if dates passed is more than 2 months.
DELIMITER ;;
DROP PROCEDURE IF EXISTS rpt_missing_payroll_files_report_test;;
CREATE PROCEDURE `rpt_missing_payroll_files_report_test`(
IN BEGIN_DATE VARCHAR(255),
IN END_DATE VARCHAR(255)
)
BEGIN
SELECT c.id,
c.name,
ip.name AS icp_name,
s.name AS country_name,
sc.name AS pm_name,
pc.frequency,
pc.check_date AS check_date,
pc.transmit_date,
IFNULL(ps.updated_at, ph.updated_at) AS submit_date,
cpp.created_at AS date_received,
ifnull(cpp.import_filename,'N/A') AS import_filename,
CASE WHEN cpp.created_at IS NOT NULL THEN 1 END AS date_received_sum,
CASE WHEN cpp.success = 1 THEN 1 END AS file_successsum,
DATEDIFF(pc.check_date,cpp.created_at) AS date_diff,
DATE_FORMAT(BEGIN_DATE,'%m/%d/%Y') AS BeginDate,
DATE_FORMAT(END_DATE,'%m/%d/%Y') AS EndDate
FROM co_payroll_calendars pc
inner join co_infos c on pc.co_info_id = c.id
inner join icp_countries icp on c.icp_country_id = icp.id
INNER JOIN sys_countries s ON icp.sys_country_id = s.id
INNER JOIN icp_infos ip ON ip.id = icp.icp_info_id
LEFT OUTER JOIN co_payroll_entry_setups ps ON pc.id = ps.co_payroll_calendar_id
LEFT OUTER JOIN co_payroll_entry_setup_histories ph ON pc.id = ph.co_payroll_calendar_id
LEFT OUTER JOIN co_payroll_processes cpp ON cpp.check_date >= (pc.check_date - INTERVAL 10 DAY ) AND cpp.co_info_id = c.id
LEFT OUTER JOIN sys_csrs sc ON c.sys_csr_id = sc.id
-- below is the part i probably need to change
WHERE (ifnull(BEGIN_DATE,'') = ''
OR pc.check_date >= BEGIN_DATE)
AND (ifnull(END_DATE,'') = ''
OR pc.check_date <= END_DATE)
GROUP BY id,
check_date
ORDER BY country_name, check_date DESC, c.id;
END;;
DELIMITER ;
The following should be allowed
CALL rpt_missing_payroll_files_report_test('2017-06-01','2017-07-01')
The following should not be allowed or limited to a certain amount of rows
CALL rpt_missing_payroll_files_report_test('2016-01-01','2017-07-01')