I have the following table of projects with their activity periods (periods are defined with FROM and TO dates):
ID | ProjID | ActiveFrom | ActiveTo
===+========+============+============
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
Of course, a project can have an arbitrary number of activity periods.
I need a SQL query (function) which will return true/false if a given project was active on some given date (is given date within some of project's activity periods).
WHERE
and some date comparisons. – Gordon Linoff Nov 20 '18 at 23:41SELECT CASE COUNT(*) WHEN > 0 THEN TRUE ELSE FALSE FROM project WHERE '2018-11-21' BETWEEN(ActiveFrom, ActiveTo)
– Antony Gibbs Nov 21 '18 at 0:04