1 CREATE DEFINER=`root`@`localhost` PROCEDURE `aac`(_id NVARCHAR(50), _startDay NVARCHAR(50), _endDay NVARCHAR(50)) 2 BEGIN 3 4 DECLARE tmpId NVARCHAR(50); 5 DECLARE tmpStartDay NVARCHAR(50); 6 DECLARE tmpEndDay NVARCHAR(50); 7 DECLARE sqlText NVARCHAR(5000); 8 9 SET @tmpId = _id; 10 SET @tmpStartDay = _startDay; 11 SET @tmpEndDay = _endDay; 12 13 SET @sqlText = 'SELECT * FROM level WHERE 1=1 '; 14 15 IF _id<>'' THEN SET @sqlText = concat(@sqlText, ' AND id=@tmpId '); END IF; 16 17 IF _startDay<>'' && _endDay<>'' THEN 18 SET @sqlText = concat(@sqlText, ' AND createdate BETWEEN @tmpStartDay AND @tmpEndDay'); 19 END IF; 20 21 PREPARE A FROM @sqlText; 22 EXECUTE A; 23 24 END