存儲過程已設置,因此用戶可以使用任何日期對其進行調用。我希望能夠限制通過兩個月的日期。如何限制在mysql存儲過程中傳遞日期的數據
當用戶在沒有選擇任何日期的情況下調用報表時,報表服務器崩潰是因爲數據太多。我希望能夠限制行如果通過日期超過2個月。
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 ;
以下應被允許
CALL rpt_missing_payroll_files_report_test( '2017年6月1日', '2017年7月1日')
以下不應該被允許或限制在一定行的量
CALL rpt_missing_payroll_files_report_test(「2016年1月1日」,「2017年7月1日」)
請注意日期應該是'DATE'類型,而不是任意'VARCHAR'字段。 – tadman