By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE projects
(`ID` int, `ProjID` int, `ActiveFrom` varchar(10), `ActiveTo` varchar(10))
;
INSERT INTO projects
(`ID`, `ProjID`, `ActiveFrom`, `ActiveTo`)
VALUES
(1, 20, '2018-01-01', '2018-01-20'),
(2, 20, '2018-02-05', '2018-02-12'),
(3, 20, '2018-02-20', '2018-02-27'),
(4, 30, '2018-01-15', '2018-02-15')
;
CREATE FUNCTION check_activity(project_id INT, check_date DATE)
RETURNS BOOLEAN
DETERMINISTIC
BEGIN
RETURN (SELECT MAX(check_date BETWEEN ActiveFrom AND ActiveTo) FROM projects WHERE ProjId = project_id);
END
SELECT check_activity(20, '2018-01-10'), check_activity(20, '2018-02-01')
check_activity(20, '2018-01-10') | check_activity(20, '2018-02-01') |
---|---|
1 | 0 |