Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

if conditions in an SQL query ?

By M.K. Verma · 4 May 2022

if conditions in an SQL query ?

If you must check whether both start_date and end_date are null or not:

SELECT l.LoginName ,p.name as project_name, p.start_date as 
project_start_date, p.end_date as project_end_date, 
pe.budget, pe.start_date, pe.end_date  
FROM project_expenses_new pe 
INNER JOIN projects p ON  pe.project_uuid=p.uuid 
INNER JOIN LoginUsers l ON pe.employee_uuid=l.uuid 
WHERE pe.employee_uuid='8a373382-c921-11ec-a7c7-005056020962' AND 

'2021-08-01' BETWEEN (case when p.start_date is null or p.end_date is null then 
pe.p.start_date else p.start_date end) and (case when p.start_date is null or p.end_date is null then pe.p.end_date else p.end_dateend);