Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use between if value is not null?

Im trying to write query where im using valid_from and valid_to but those values can be null or one of them.

select * from omr_approval_teams where now() between valid_from and valid_to ;

This is my query, so i want to return data using if both valid_from and valid_to is null, or both not null or only valid_to is null. Any suggestion how can i achive that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could just explicitly add passes for null date bounds:

SELECT *
FROM omr_approval_teams
WHERE (NOW() >= valid_from OR valid_from IS NULL) AND
      (NOW() <= valid_to   OR valid_to IS NULL);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading