'Shorten the procedure
Is it possible to somehow shorten the procedure without using if, but use if in where?
CREATE DEFINER=`root`@`localhost` PROCEDURE `getMailing`(in user_id int, by_no_activate boolean)
BEGIN
if by_no_activate then
select `name`, send_time, `type`, `active` from mailing where `userId` = user_id and `active` = False and send_type != 'now';
else
select `name`, send_time, `type`, `active` from mailing where `userId` = user_id;
end if;
END
Solution 1:[1]
You can put an IF() condition in the WHERE clause.
SELECT `name`, send_time, `type`, `active`
from mailing
where `userId` = user_id
AND IF(by_no_activate, `active` = False and send_type != 'now', TRUE)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barmar |
