我正在尝试在MySQL Workbench中创建一个存储过程。
我需要检查某个标志是否等于1.如果该标志等于1,则按FollowupDate
搜索,否则使用QuoteDate
IF(qFollowup = 1) THEN
IF(pFromFollowupDate != '') THEN
BEGIN
SET @Main = CONCAT(@Main, ' AND DATE(q.FollowupDate) >= \'',pFromFollowupDate,'\' ');
END;
ELSE
IF(pFromDate != '') THEN
BEGIN
SET @Main = CONCAT(@Main, ' AND DATE(q.QuoteDate) >= \'',pFromDate,'\' ');
END;
END IF;
END IF;
当我尝试应用更改时,它说有语法错误。
答案 0 :(得分:0)
尝试:
DELIMITER //
CREATE PROCEDURE `sp_name`()
BEGIN
IF qFollowup = 1 THEN
IF pFromFollowupDate != '' THEN
SET @Main = CONCAT(@Main, ' AND DATE(q.FollowupDate) >= \'',pFromFollowupDate,'\' ');
ELSE
IF pFromDate != '' THEN
SET @Main = CONCAT(@Main, ' AND DATE(q.QuoteDate) >= \'',pFromDate,'\' ');
END IF;
END IF;
END IF;
END//
DELIMITER ;