这是我的存储过程
DELIMITER $$
DROP PROCEDURE IF EXISTS `simplesign`.`GetTenantTaskBetweenDate` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetTenantTaskBetweenDate`(
IN tid VARCHAR(100),
IN fromdate DATE ,
IN todate DATE,
IN searchvalue VARCHAR(100)
)
BEGIN
SELECT RequestID
FROM task
WHERE ( (TenantID=tid)
AND Create_date BETWEEN fromdate AND todate)
AND (File_name LIKE searchvalue || File_title LIKE searchvalue)
ORDER BY Create_date DESC;
END $$
DELIMITER ;
在以下情况下,我希望ReuestID
表中的所有task
:
(select * from)
请帮我解决这个问题。
答案 0 :(得分:2)
听起来你不想使用所有条件,如果它们不是空的
DELIMITER $$
DROP PROCEDURE IF EXISTS `simplesign`.`GetTenantTaskBetweenDate` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetTenantTaskBetweenDate`(
IN tid VARCHAR(100),
IN fromdate DATE ,
IN todate DATE,
IN searchvalue VARCHAR(100)
)
BEGIN
SELECT RequestID
FROM task
WHERE (tid is null OR TenantID=tid)
AND (fromdate is null OR Create_date >= fromdate)
AND (todate is null OR Create_date <= todate)
AND (searchvalue is null OR File_name LIKE searchvalue OR File_title LIKE searchvalue)
ORDER BY Create_date DESC;
END $$
DELIMITER ;