I want to write a query to select the records where today's date (sysdate) is in between the start_date and end_date and also if the end_date is not present (Null) then I have to add sysdate 1 which means(today is 07-01-2022 so it should become 8-01-2022) and show it in output
Records present in the table :
(1,'01-01-2022','09-01-2022'), (2,'02-01-2022',null ), (3,'31-12-2022','01-01-2022')
Thanks
CodePudding user response:
Try this:
SELECT * FROM orders WHERE CURRENT_DATE BETWEEN start_date AND COALESCE(end_date, CURRENT_DATE 1)
Few additional points on the script,
CURRENT_DATE would give you the system date and
COALESCE will check for null in 'end_date' and use CURRENT_DATE 1